fix(react): cancel session account initialization on unmount - #295
fix(react): cancel session account initialization on unmount#295Jr-kenny wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 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".
| return () => { | ||
| cancelledRef.current = true; |
There was a problem hiding this comment.
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 👍 / 👎.
Problem
useSessionAccountalready 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
storagePrefixduring rerenders does not cancel a live initialization. The regression test holdssyncState()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.