fix: externalize useSyncExternalStore shim to fix App Router crash#760
Conversation
Bundling use-sync-external-store/shim (a CJS module) into the ESM dist makes rolldown emit a dynamic require() that throws "dynamic usage of require is not supported" when a reactfire data hook loads client-side in a Next.js App Router (strict ESM) context. This regression shipped in 4.2.4 and 4.2.5; 4.2.3 predates the current build toolchain and is clean. Externalizing the shim lets the consumer's bundler resolve it (it is already a runtime dependency), removing the require from our dist while keeping the shim's React 16/17 fallback. Verified the throw path is absent from the built ESM dist and from a rebuilt Next.js App Router client chunk.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
@jhuleatt flagging this for an expedited 4.2.6, since it is a regression in What: reactfire 4.2.4 and 4.2.5 crash on the client whenever a data hook renders. The bundled Blast radius (runtime-confirmed): reproduced live in both a Next 16 App Router app (turbopack) and a Vite SPA on published 4.2.5, so it spans the two most common modern reactfire setups, not one bundler. Server prerender is unaffected (Node has Fix (this PR): one-line Vite Since you are the manual publish path, this needs you for the 4.2.6 release once reviewed. Separately: this is the second dist-level regression to ship as a patch (after the 4.2.4 |
Fixes #759
Summary
Reactfire 4.2.4 and 4.2.5 crash on the client whenever a data hook renders, in any browser bundle that does not expose
require.use-sync-external-store/shim(CJS) gets bundled into our ESMdist, which makes the bundler emit a dynamicrequire(). In a strict-ESM browser context that throws at module evaluation:4.2.3 predates the current build toolchain and is clean.
Fix
Add
use-sync-external-store/shimto the Viteexternalsso the consumer's bundler resolves it (it is already a runtimedependency). This removes therequirefrom our dist while keeping the shim's React 16/17 fallback, so it stays non-breaking (no peer-range change).Verification
dist/index.js:requireoccurrences 3 to 0; cleanimport ... from "use-sync-external-store/shim".status: 'success').Patch-level, non-breaking. Fixes the regression in
latest. Version bump to 4.2.6 left as a separate publish-time commit, per convention.