feat(plugin-rsc): expose Node.js stream APIs - #1276
Conversation
There was a problem hiding this comment.
Thanks for PR. There has been some update on current /rsc structure https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/README.md#rsc-runtime-react-server-dom-api Can you align these node variant with new structure and API like:
/rsc.node/rsc/server.node/rsc/client.node/rsc/static.node
Having an e2e would be also desired. A dedicated starter-like example under examples/node-stream could work. I have reworked test guidance a bit recently so please take a look https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-rsc/CONTRIBUTING.md#testing
… createFromNodeStream) Re-export Node.js-native stream variants from react-server-dom-webpack as new entry points (@vitejs/plugin-rsc/rsc.node, ssr.node) without duplicating existing code — each .node file re-exports from its edge counterpart and adds only the Node-specific APIs. Closes vitejs#1162 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restructure Node.js stream entry points from flat paths (/rsc.node, /ssr.node) to match the existing sub-path pattern: - /rsc/server.node (renderToPipeableStream) - /rsc/client.node (createFromNodeStream) - /rsc/static.node (prerenderToNodeStream) - /rsc.node (barrel re-export of server.node + client.node) Add .node vendor subpaths to optimizeDeps.include so CJS vendor files are properly pre-bundled in dev mode. Add examples/node-stream demonstrating Node.js stream APIs with an e2e test covering both dev and build modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7747f53 to
b1baf48
Compare
|
Rebased the branch and updated everything based on your feedback. Node stream apis are now aligned with the sub-path pattern. Also added an e2e test. Thanks |
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
hi-ogawa
left a comment
There was a problem hiding this comment.
I have extended node stream entries to @vitejs/plugin-rsc/ssr.node too. examples/node-stream is also extended to exercise node stream workflow end to end accordingly.
The re-exports from edge to node is eliminated by copying own wrapper code on node variant entries.
Co-authored-by: OpenCode <noreply@opencode.ai>
| rsc: { | ||
| optimizeDeps: { | ||
| include: [ | ||
| '@vitejs/plugin-rsc/vendor/react-server-dom/server.node', | ||
| '@vitejs/plugin-rsc/vendor/react-server-dom/static.node', | ||
| '@vitejs/plugin-rsc/vendor/react-server-dom/client.node', |
There was a problem hiding this comment.
Moved the node vendor optimizeDeps.include to example level configuration since always adding optimized node import from plugin can cause issues on non-node environment.
Edit: Apologies, Claude went ahead and opened this PR automatically. This code was driven with Claude.
This closes my issue #1162 and addresses the feedback from the PR in #1164
Let me know if you want me to make any changes. Sorry for the quick trigger on the PR.
The flaw here is dual loading edge and node apis on the node path – if we want to refactor it, we can drop that. You'd know better than me if that's a big deal.
Closes #1162
The vendored
react-server-dom-webpackpackage includes Node.js stream APIs (renderToPipeableStream,createFromNodeStream) that are faster than their Web Streams equivalents on Node.js, but they weren't exposed by@vitejs/plugin-rsc.Approach
The
server.nodeandclient.nodevariants fromreact-server-dom-webpackare supersets of their.edgecounterparts. So each new.nodefile re-exports everything from the existing edge-based module and adds only the Node.js-specific delta — no code duplication.New entry points:
Both also re-export all existing Web Streams APIs, so consumers can switch entry points without losing access to
renderToReadableStream/createFromReadableStream.Files
New (4 files):
src/react/rsc.node.ts— low-level wrapper, re-exports./rsc+ addsrenderToPipeableStreamsrc/react/ssr.node.ts— low-level wrapper, re-exports./ssr+ addscreateFromNodeStreamsrc/rsc.node.tsx— high-level entry, re-exports./rsc+ adds wrappedrenderToPipeableStreamwith asset manifest enrichmentsrc/ssr.node.tsx— high-level entry, re-exports./ssr+ addscreateFromNodeStreamModified (2 files):
tsdown.config.ts— added 4 new entry pointssrc/types/index.ts— addedPipeableStream,RenderToPipeableStreamOptions,CreateFromNodeStreamOptionsNo changes to
package.json(wildcard export covers new paths) orplugin.ts(vendor alias already handles.nodevariants).Test plan
pnpm buildcompiles successfully with new entry pointstsc -b ./tsconfig.jsonpassescreateFromNodeStream)