Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 1, 2025

Description

This PR changes the approach of running preamble code for hmr. Instead of using inline script of transformIndexHtml, we can heuristically target react code by __REACT_DEVTOOLS_GLOBAL_HOOK__ and inject preamble virtual.

This will likely cause doubly running preamble for some ssr frameworks which already injects it manually without transformIndexHtml, but it seems actually fine. @vitejs/plugin-rsc have the following logic and CI here didn't break (EDIT: I updated packages/common/refresh-runtime.js so injectIntoGlobalHook happens only once)

FYI, the idea of injecting to React code is something @vitejs/plugin-rsc did to handle AsyncLocalStorage:

`globalThis.AsyncLocalStorage = __viteRscAsyncHooks.AsyncLocalStorage;` +
code

TODO

@hi-ogawa hi-ogawa force-pushed the 10-01-feat_auto_inject_hmr_preamble_without_transformindexhtml_ branch from 3f41a2a to bab8a7b Compare October 1, 2025 12:27
@hi-ogawa hi-ogawa changed the title feat: auto inject hmr preamble without transformIndexHtml feat: auto inject hmr preamble without transformIndexHtml Oct 1, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review October 1, 2025 14:37
@hi-ogawa hi-ogawa changed the title feat: auto inject hmr preamble without transformIndexHtml refactor: auto inject hmr preamble without transformIndexHtml Oct 1, 2025
@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Oct 4, 2025

Closed in favor of #890

@hi-ogawa hi-ogawa closed this Oct 4, 2025
@hi-ogawa hi-ogawa deleted the 10-01-feat_auto_inject_hmr_preamble_without_transformindexhtml_ branch October 4, 2025 10:32
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.

1 participant