Skip to content

fix(ui): ignore an empty server echo while a card pile is still local - #91

Open
0froq wants to merge 2 commits into
antfu:mainfrom
0froq:fix/card-pile-empty-echo
Open

0froq wants to merge 2 commits into
antfu:mainfrom
0froq:fix/card-pile-empty-echo

Conversation

@0froq

@0froq 0froq commented Nov 17, 2026 •

Copy link
Copy Markdown

🔗 Linked issue

resolves #90

🧭 Context

sharedState.get returns the empty initial value before the server answers. start() has already built a pile by then. Applying that empty echo clears it, and the next save stores the empty pile. Advancing after that can show an empty detail for a card that still has an issue number.

📚 Description

Subscribe to updated before the first read, and do not apply the initial value when that read times out. If a pile already exists locally, ignore an empty server value so a late echo cannot wipe it. dismiss() still clears the pile, because it empties the local state before writing null.

snapshot() now passes plain objects into mutate. source and options are
Vue reactive proxies, and immer throws when it reads them back off a frozen draft.

ui/composables/useCardsMode.test.ts starts a pile of two issues, then emits the empty server value only after sharedState.get resolves. Before this change the assertion receives []. With it, both the local pile and the saved pile stay [2, 1].

This is the first test that loads ui/ code from the root Vitest run, and vue is only installed for the UI package. vitest.config.ts aliases it to that copy. Drop the alias and the test if you would rather not run UI code from here ❤️

sharedState.get returns the empty initial value before the server reply.
Applying that reply after start() built a pile cleared it, and the next
save persisted the empty pile.
sharedState.get resolves after start() has already built the pile. The
test emits the empty server value in that window, which used to clear
the pile and persist it.
@0froq
0froq force-pushed the fix/card-pile-empty-echo branch from a051ad4 to 89f0fcb Compare November 17, 2026 05:42
@0froq

0froq commented Nov 17, 2026

Copy link
Copy Markdown
Author

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/antfu/ghfs/91?from=0froq

raw result

💭 analyzed by openai-compatible/opencode-go/deepseek-v4.1-flash
🕰️ 2026-11-17 05:43 UTC
🔗 head 89f0fcb
🤖 automated by pulls.review

{
  "headSha": "89f0fcb20ac4e201c43f5f47468f7f89a0d93231",
  "result": {
    "overallSummary": "Fixes #90: `sharedState.get` returns the empty initial value before the server replies, and that late echo could overwrite a card pile that `start()` had just built locally — which then got persisted as an empty pile. The fix subscribes to `updated` before the first read, skips applying the value when that read times out, and ignores an empty server value while a local pile exists. `snapshot()` now hands immer plain objects instead of Vue reactive proxies.",
    "groups": [
      {
        "key": "card-pile-echo",
        "label": "Card pile echo handling",
        "category": "core",
        "filePaths": [
          "ui/composables/useCardsMode.ts"
        ],
        "fileNotes": [
          {
            "path": "ui/composables/useCardsMode.ts",
            "text": "The new guard in `applyServerState` drops any empty incoming state while a local pile exists. That is what keeps a late echo from wiping a fresh pile, but it also means a legitimate remote clear (another client calling `dismiss()`) will no longer propagate to this client. `dismiss()` works only because it empties the local state before writing `null`."
          },
          {
            "path": "ui/composables/useCardsMode.ts",
            "text": "`waitForFirstUpdate` now resolves a boolean so the initial value is only read back when the server actually answered; the timeout path must not apply anything or it reintroduces the wipe. `snapshot()` deep-copies `pile`/`processedOps` and unwraps `source`/`options` with `toRaw` because immer freezes the draft and Vue proxies refuse reads on a frozen object."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Regression test and test config",
        "category": "tests",
        "filePaths": [
          "ui/composables/useCardsMode.test.ts",
          "vitest.config.ts"
        ],
        "fileNotes": [
          {
            "path": "vitest.config.ts",
            "text": "The `vue` alias points at the copy pnpm installed for the UI package (the root has no `vue` dependency), so it depends on the `.pnpm/node_modules` layout staying stable."
          }
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-17T05:43:53.718Z",
    "model": "openai-compatible/opencode-go/deepseek-v4.1-flash",
    "locale": "en"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Card pile is cleared by an empty shared-state echo right after start

1 participant