-
-
Notifications
You must be signed in to change notification settings - Fork 205
feat(react): expose virtual module to simplify hmr preamble setup on ssr #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react): expose virtual module to simplify hmr preamble setup on ssr #890
Conversation
|
superseded by #891 |
|
Okay, I think I want this one instead of #891 as patching react isn't great. |
Let's push this to upstream vitejs/vite-plugin-react#890
- Fix typos: "intiialize" → "initialize", "intiialization" → "initialization" - Fix grammar: "a following" → "the following" - Improve wording for clarity and conciseness 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add preamble section to plugin-react-swc README - Update CHANGELOG entries for both plugin-react and plugin-react-swc - Document the new virtual module feature for SSR HMR setup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
If we add support for |
| "./refresh-runtime": "./refresh-runtime.js" | ||
| }, | ||
| "dependencies": { | ||
| "@rolldown/pluginutils": "1.0.0-beta.41" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added to SWC deps too (and maybe rsc) because the common package in bundled into react plugins. I'm not a power user of pnpm, but is catalog the best way to unsure it's the same version everywhere?
Also should we use a strict version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this might look weird but I just noticed @rolldown/pluginutils is already in dependencies of all three react packages (and rsc doesn't use it) and they are all pinned with same version. So this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ok with dependabot this should be done in sync 👍
That sounds better, but I'm actually not sure how that works. Would that be something like this? {
transform: {
order: 'post',
handler(code, id) {
const info = this.getModuleInfo(id);
if (info?.isEntry) {
return `import "..";` + code;
}
}
}
} |
I was thinking about a code like below as {
transform: {
order: 'post',
handler(code, id, { isEntry }) {
if (isEntry) {
return `import "..";` + code;
}
}
}
}But turns out |
| datasource | package | from | to | | ---------- | -------------------- | ----- | ----- | | npm | @vitejs/plugin-react | 5.0.4 | 5.1.0 | ## [v5.1.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#510-2025-10-24) ##### Add `@vitejs/plugin-react/preamble` virtual module for SSR HMR ([#890](vitejs/vite-plugin-react#890)) SSR applications can now initialize HMR runtime by importing `@vitejs/plugin-react/preamble` at the top of their client entry instead of manually calling `transformIndexHtml`. This simplifies SSR setup for applications that don't use the `transformIndexHtml` API. ##### Fix raw Rolldown support for Rolldown 1.0.0-beta.44+ ([#930](vitejs/vite-plugin-react#930)) Rolldown 1.0.0-beta.44+ removed the top-level `jsx` option in favor of `transform.jsx`. This plugin now uses the `transform.jsx` option to support Rolldown 1.0.0-beta.44+.
| datasource | package | from | to | | ---------- | -------------------- | ----- | ----- | | npm | @vitejs/plugin-react | 5.0.4 | 5.1.0 | ## [v5.1.0](https://github.com/vitejs/vite-plugin-react/blob/HEAD/packages/plugin-react/CHANGELOG.md#510-2025-10-24) ##### Add `@vitejs/plugin-react/preamble` virtual module for SSR HMR ([#890](vitejs/vite-plugin-react#890)) SSR applications can now initialize HMR runtime by importing `@vitejs/plugin-react/preamble` at the top of their client entry instead of manually calling `transformIndexHtml`. This simplifies SSR setup for applications that don't use the `transformIndexHtml` API. ##### Fix raw Rolldown support for Rolldown 1.0.0-beta.44+ ([#930](vitejs/vite-plugin-react#930)) Rolldown 1.0.0-beta.44+ removed the top-level `jsx` option in favor of `transform.jsx`. This plugin now uses the `transform.jsx` option to support Rolldown 1.0.0-beta.44+.
Description
This PR adds virtual module
@vitejs/plugin-react/preamble, which allows SSR app to easily enable HMR by adding import side effect at the top of client entry without handlingtransformIndexHtml. Seeplayground/ssr-react/src/entry-client.jsxfor example.