test: cover Suspense retries in React streaming SSR#17
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb342110ed
ℹ️ 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".
| if (isServerEnvironment) { | ||
| const token = Symbol("pending-server-dispose"); | ||
| nextState.pendingDisposeToken = token; | ||
| schedulePendingDispose(stateRef, nextState.instance, token); | ||
| } |
There was a problem hiding this comment.
Delay server disposal until render completion
useMolecule now schedules disposal as soon as the hook creates a server-side instance, but in streaming SSR (renderToPipeableStream / renderToReadableStream) a component can suspend and be retried later in the same request. In that case this microtask can run before the retry, so onDispose fires mid-render and the molecule is recreated on resume, which can duplicate teardown/setup side effects and break code that expects disposal only after the full server render finishes. This is introduced by scheduling from render-time rather than from a stream completion signal.
Useful? React with 👍 / 👎.
Purpose
Extend the React adapter SSR test coverage so streaming Suspense retries cannot regress molecule cleanup behavior.
Summary
useMoleculeusing aReact.use()-based test fixture.renderToPipeableStreamkeeps suspended molecules undisposed at shell time and disposes every server-created instance after retries finish.renderToReadableStreamalso disposes every retry-created molecule instance and keeps mount-time work disabled on the server.Verification
pnpm test packages/__tests__/useMolecule.ssr.test.tsxpnpm testpnpm typecheckpnpm buildmise run ci