Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react-server/src/features/assets/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function vitePluginServerAssets({
if (!manager.buildType) {
// extract <head> injected by plugins
let { head } = await getIndexHtmlTransform($__global.dev.server);
head = head.replace(
'<script type="module">',
'<script type="module" async>',
);
Comment on lines +31 to +34
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without async attribute, http://localhost:5173/test/loading/1 ("hydrate while streaming" example) fails by

chunk-3WLTBFGF.js:9 Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
    at chunk-3WLTBFGF.js:9:11


// serve dev css as ?direct so that ssr html won't get too huge.
// then remove this injected style on first hot update.
Expand Down
10 changes: 5 additions & 5 deletions packages/react-server/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ export function vitePluginReactServer(
// wrapper entry to ensure client entry runs after vite/react inititialization
return /* js */ `
import "${SERVER_CSS_PROXY}";
import RefreshRuntime from "/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
// import RefreshRuntime from "/@react-refresh";
// RefreshRuntime.injectIntoGlobalHook(window);
// window.$RefreshReg$ = () => {};
// window.$RefreshSig$ = () => (type) => type;
// window.__vite_plugin_react_preamble_installed__ = true;
Comment on lines +456 to +460
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Practically speaking, we shouldn't have to worry about race condition since head script should finish first, so we don't need manual preamble injection.

await import("${entryBrowser}");
`;
}
Expand Down