Skip to content

fix(react): cancel session account initialization on unmount - #295

Open
Jr-kenny wants to merge 1 commit into
0xMiden:mainfrom
Jr-kenny:Jrkenny/fix-session-account-unmount
Open

fix(react): cancel session account initialization on unmount#295
Jr-kenny wants to merge 1 commit into
0xMiden:mainfrom
Jr-kenny:Jrkenny/fix-session-account-unmount

Conversation

@Jr-kenny

@Jr-kenny Jr-kenny commented Aug 14, 2026

Copy link
Copy Markdown

Problem

useSessionAccount already passed a cancellation ref through its funding poll, but nothing set it when the hook unmounted. A screen could leave while initialization kept polling, and a later funding note could still trigger a consume transaction.

Fix

The hook now marks in-flight initialization as cancelled from an unmount-only effect. The cleanup is separate from session restoration so a changing storagePrefix during rerenders does not cancel a live initialization. The regression test holds syncState() open across unmount and checks that no note lookup or consume submission happens afterwards.

Closes #288

Testing

The full React SDK suite passes with 62 test files and 846 tests. I also ran the React typecheck, lint, and package build. Lint reports the repository existing unused-disable warnings, with no errors.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 606078247a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +94 to +95
return () => {
cancelledRef.current = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recheck cancellation after the note lookup

When unmount occurs while waitAndConsume() is awaiting getConsumableNotes(), this cleanup sets the ref, but the helper does not read it again before constructing and submitting the consume transaction. A funding note returned after unmount therefore still triggers precisely the transaction this change is intended to prevent; check cancellation immediately after the note lookup and cover that pending phase in the lifecycle test.

Useful? React with 👍 / 👎.

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.

useSessionAccount never cancels an in-flight initialize() on unmount — polling and note consumption continue after the component is gone

1 participant