Skip to content

fix(client): ignore stale import previews after a new file pick - #75

Merged
cloader merged 1 commit into
cloader:devfrom
timacek:fix/import-preview-request-token
Nov 1, 2026
Merged

cloader merged 1 commit into
cloader:devfrom
timacek:fix/import-preview-request-token

Conversation

@timacek

@timacek timacek commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

This PR targets dev and does one thing only: make the import preview follow the currently picked file. No host changes.

改了什么? / What changed?

The JSON-import dry-run preview was not tied to the file that produced it. onFile switched the
document synchronously, then unconditionally applied whichever importPreview promise resolved
last. Picking file A and then file B before A's round-trip returned could display A's
classification while the Run button committed B — in replace mode that is a whole-ledger swap
justified by a preview the user never saw.

  • src/client/board/ImportModal.tsx — add a monotonic pick sequence (useRef). Both async
    continuations (file.text() and controller.importPreview) now ignore results that no longer
    belong to the current pick, and the parse-error path is guarded the same way.
  • tests/import-preview-order.spec.tsx — new regression test: two picks, deferred previews
    resolved out of order (B then A). It asserts the displayed create/overwrite stats stay B's and
    that Run commits B's payload. Red/green: without the source change the test fails on the stats
    assertion.

如何验证? / How verified?

  • npx vitest run tests/import-preview-order.spec.tsx — passes with the fix; fails when only
    ImportModal.tsx is reverted.
  • npx tsc --noEmit — clean.
  • npx vitest run — 46 files / 603 tests pass (includes the new spec).
  • npm run build — clean.

Environment: Windows 11, Node 26.13, DSH 0.2.1-rc.5, branch rebased on dev @ fb97e7f.

Note: on Node 26 the suite additionally needs the jsdom localStorage setup discussed in #71; CI
(Node 22) is unaffected by that.

关联 Issue / Related issue

Fixes #72.

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.

[bug] JSON import: a stale preview can authorize committing a different file than the one the user reviewed

2 participants