Skip to content

fix(react): correct SSR behavior in direct Markdown rendering - #11

Open
SoonIter wants to merge 4 commits into
mainfrom
soon-codex/use-official-react-ssr
Open

SoonIter wants to merge 4 commits into
mainfrom
soon-codex/use-official-react-ssr

Conversation

@SoonIter

@SoonIter SoonIter commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

The direct Markdown renderer executes imperative handles, refs, and class commit lifecycles in Node.js and silently ignores render errors. Correct these behaviors while retaining the custom reconciler and direct Markdown serialization.

Modification

Before/after below compares the PR base (6d6cfb9) with this implementation. \n denotes a newline in the returned string.

Input / trigger Before After
A class renders <p ref={recordRef}>Content</p> and records componentDidMount Returns "Content\n\n"; calls the ref and mount callback Returns the same Markdown; neither callback runs
useImperativeHandle(ref, createHandle) records a call or accesses window Executes createHandle in Node.js Skips createHandle, matching Fizz
A component throws new Error('Broken') Resolves with "" when DEBUG is unset Rejects with the original error
The same error is wrapped in a class boundary returning <p>Fallback</p> Resolves with "Fallback\n\n" Rejects with the original error; class error handlers may still run
<Suspense fallback={<p>Loading</p>}><Async /></Suspense>, where Async reads a pending promise that resolves to "Resolved content" Returns "Loading\n\n" before content resolves Waits, then returns "Resolved content\n\n"; refs and class commit lifecycles remain suppressed through reveal and fallback deletion

The implementation also:

  • Uses Fizz values for transitions, optimistic state, deferred values, and external-store server snapshots. Transition/optimistic updates during rendering throw; external stores never subscribe. Initial deferred output is preserved: useDeferredValue('current', 'initial') returns 'initial', no initial value returns 'current', and a null initial value stays null.
  • Temporarily masks Fiber refs and class instances during commits, including Suspense reveal and deletion, while leaving user instances unchanged and preserving error callbacks.
  • Synchronously unmounts completed or rejected roots before removing hook interception. A suspended sibling of a rejected render cannot resume later with client effects; another concurrent render can still finish normally.

Validation

46 tests pass in development and production modes. Coverage includes an independent react-dom/server streaming control for Suspense lifecycle suppression, asynchronous rejection after suspension, deferred-value branches, distinct concurrent IDs/context values, and rejected-root cleanup alongside a healthy render. Assertions on error callbacks run outside React so React cannot swallow assertion failures. Builds, TypeScript, Biome, and Publint pass; production ESM/CJS entry points passed the reveal and rejected-retry reproductions.

Remaining differences

  • useId retains the client reconciler format (_r_…_), rather than Fizz's tree-based server IDs (_R_…_).
  • Errors inside Suspense strictly reject Markdown generation. React server rendering can instead emit fallback HTML and defer recovery to the client.
  • Class boundaries may execute their error handlers, while Fizz skips them. Their fallback is not accepted as successful Markdown.
  • The action-state comparison covers initial state and pending values only; it does not establish server-action dispatch or form-postback support.
  • Internal Fiber access is tied to pinned react-reconciler 0.33.0 and covered by behavior tests.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 08:24
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-12T08:24:14.789896Z
We couldn’t complete this review. Comment @codex review to try again.
2f9996a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@SoonIter
SoonIter force-pushed the soon-codex/use-official-react-ssr branch from 2f9996a to 6883d75 Compare November 12, 2026 08:24
@SoonIter SoonIter changed the title refactor(react): delegate SSR execution to react-dom/server fix(react): correct SSR behavior in direct Markdown rendering Nov 12, 2026

This branch has not been deployed

No deployments
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.

2 participants