Repository navigation
fix(ui-react): one React in the production SSR bundle under pnpm - #44
Merged
Merged
Conversation
|
Caution Review failedThe pull request is closed. TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.
|
🦋 Changeset detectedLatest commit: e6eca00 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
cursor Bot
pushed a commit
that referenced
this pull request
Nov 6, 2026
…ckCms(); SSR smoke in test:build) Co-authored-by: jherr <jherr@pobox.com>
cursor Bot
pushed a commit
that referenced
this pull request
Nov 6, 2026
Co-authored-by: jherr <jherr@pobox.com>
cursor
Bot
force-pushed
the
cursor/blog-ssr-react-dedupe-d21e
branch
from
November 6, 2026 14:50
e202a53 to
0bf5729
Compare
Chain step 2 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order. Co-authored-by: jherr <jherr@pobox.com>
jherr
force-pushed
the
cursor/blog-ssr-react-dedupe-d21e
branch
from
November 6, 2026 15:05
0bf5729 to
e6eca00
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge chain: step 2 of 24. Base:
main. Merge it right after #41. The branch ismain3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit0bf5729(tree4e30daa).What
Running
node .output/server/index.mjsforexamples/blogreturned 500 on every server-rendered page:TypeError: Cannot read properties of null (reading 'useRef'), an invalid hook call. Eight other examples did the same. Dev and E2E were fine, because both run on the Vite dev server.Root cause
The production server bundle loaded two copies of React.
@tanstack/react-storeimports the CommonJSuse-sync-external-storeshim, which callsrequire('react'). ui-react's auth hooks use react-store, and so do@tanstack/react-formand@tanstack/search-ui-react.require('react')as acreateRequirecall, which Nitro can't trace. At runtime that call loaded a second React fromnode_modules/.pnpm.When it started. I bisected with a production build and boot at each step.
81a5990(the 1.0 alpha) is good. The first bad commit isb375842(2026-11-03), which moved the admin's auth onto@tanstack/react-store. So the bug predates the refactor and #14.Who was affected (production build, then boot, on
main3b4a112)examples/blog,blog-voting,db-federated,db-sqlite,picksexamples/{wordpress,emdash,payload,astro-starlight}-afterexamples/db-markdown(doesn't use ui-react)app/base,app/prm(already work around it withssr.externaland a direct react-store dependency)starters/*The fix
tanstackCms()(packages/ui-react/src/vite.ts). In SSR, it resolves the shim's entry points to two virtual modules:useSyncExternalStore;with-selectoris an ESM port of React's own implementation (MIT, Meta).Both import React like any other module, so Nitro bundles exactly one React. Every app that uses the plugin gets the fix with no config change. Client builds are untouched.
Five examples now use the plugin.
blog-votingand the four*-afterexamples listedssr.noExternalby hand instead of usingtanstackCms(), so the package fix couldn't reach them. The migration skills already say to use the plugin.Changeset and docs. A
@tanstack/cms-ui-reactpatch changeset, and one sentence inroutes-in-a-package.md.Regression check
scripts/smoke-ssr.mjsboots.output/server/index.mjson a free port with a throwaway data directory. It requests/,/admin,/contentand/admin/content, because most examples mount the admin at the root. It fails in four cases:test:buildin the nine ui-react examples.pnpm test:ciandtest:pralready run that target afterbuild.nx.jsonnow caches.outputand keystest:buildon^production.knip.jsonregisters the script.packages/ui-react/tests/vite-plugin.test.tsxadds 4 tests:with-selector: it renders underrenderToString, re-renders on a store update, and skips a re-render whenisEqualholds.vite.tschange reverted,blog:test:buildfails with 500s and "Invalid hook call".Breaking changes
None. In SSR, apps now get React's built-in
useSyncExternalStoreinstead of the shim's. That hook ships in React 18 and later, and ui-react already requires React 19.How verified
GitHub Actions is out of billing, so everything ran locally with
--skip-nx-cache, on heade202a53on top ofmain3b4a112.pnpm install --frozen-lockfilepnpm test:ci@tanstack/cms-api:test:oxlintfails. ui-react 89, including the 4 new tests. Every starter and example passes. Kiira 124/124. Knip is clean.test:build, insidetest:ci/and/content(/admin/contentfor payload-after) return 200, and the rest return 404.pnpm test:dtspnpm test:scriptspnpm test:dialectsreadDocument (test)at 248 is drift that's already on main.I also checked separately:
blog:test:buildpasses, and the booted blog server returns 200 on/, where it returned 500 on main.Assumptions
with-selectorport follows React's source./admincan be a 404 where the admin is mounted at the root. The script still requires at least one path below 400.app/baseandapp/prmworkarounds stay for now. They're redundant after this PR; removing them is a follow-up.Overlap with the 1d/R2 stack
1d (#28) also changes
packages/ui-react/src/vite.ts: its imports, the doc comment and thetanstackCms()options. It also changes thecmsVirtualRoutesimport line in the five example configs. Expect small, mechanical conflicts there. Noroutes/*files are touched.This PR is independent of the refactor stacks.
Merge chain (local verification, CI down)
This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied. No conflicts.
The chain tip's tree is exactly the integration rehearsal plus #46 (
c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the newmain; that rebase is always clean.