Skip to content

Conversation

@hi-ogawa
Copy link

@hi-ogawa hi-ogawa commented Apr 24, 2025

Hello! This is related to client reference preinit/preload we've been talking. For SSR prepare destination (which Parcel correctly implements), (react-server-dom-xxx/client).createFromReadableStream needs to be triggered inside (react-dom/server).renderToReadableStream. There was a conversation on react-server-dom-parcel PR facebook/react#31799 (comment)

I just hacked around decode and renderHtml to verify this, but this probably means react router side needs to adjust how routeRSCServerRequest works. This feels like React side limitation, so probably they might find a way to avoid this gotcha, but just sharing it here in case you find it useful.

Also I verified it on my Vite plugin example with the same hack hi-ogawa/vite-plugins#765 (but note that, in my case with react-server-dom-webpack, I'm not using builtin chunks system, but rather calling ReactDOM.preloadModule manually during __webpack_require__ https://github.com/hi-ogawa/vite-plugins/blob/2bf1040130352cab6ce6d47107fbd477637b8447/packages/rsc/src/ssr.ts#L11-L39).

How to verify

curl http://localhost:3000/about
  • before
<head>
  <meta charSet="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>React Router Parcel</title>
</head>
  • after
<head>
  <meta charSet="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script src="/client/server.8e6eebd4.js" type="module" async=""></script>
  <script src="/client/root.8bb36921.js" type="module" async=""></script>
  <script src="/client/about.a4f2d2cb.js" type="module" async=""></script>
  <title>React Router Parcel</title>
</head>

@devongovett
Copy link
Contributor

You could also check out how Parcel's @parcel/rsc wrapper library is implemented, or maybe use it directly instead of the low level API? If there's functionality missing, please let me know. https://github.com/parcel-bundler/parcel/blob/v2/packages/utils/rsc/src/server.tsx

@jacob-ebey
Copy link
Owner

This is solved in RR itself, no need for this: remix-run/react-router#13467

@jacob-ebey jacob-ebey closed this May 2, 2025
@hi-ogawa hi-ogawa deleted the fix-client-reference-prepare-destination branch May 2, 2025 05:24
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.

3 participants