-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Client hmr injection heuristics break workers that are not using react #6148
Comments
https://github.com/vitejs/vite/blob/main/packages/plugin-react/src/index.ts#L121 // react
export function Thing() { return 1 } maybe can fix that by skipping the worker file when transforming |
…vitejs#6148)" This reverts commit 136883d.
* fix: reactPlugin skip inject react hmr code to workerFile (fix #6148) * Revert "fix: reactPlugin skip inject react hmr code to workerFile (fix #6148)" This reverts commit 136883d. * fix(plugin-react): check for import React statement in .js files …instead of using naïve `code.includes("react")` check Co-authored-by: Alec Larson <[email protected]>
…ejs#6320) * fix: reactPlugin skip inject react hmr code to workerFile (fix vitejs#6148) * Revert "fix: reactPlugin skip inject react hmr code to workerFile (fix vitejs#6148)" This reverts commit 136883d. * fix(plugin-react): check for import React statement in .js files …instead of using naïve `code.includes("react")` check Co-authored-by: Alec Larson <[email protected]>
Describe the bug
If a worker uses a source file that both includes the word "react" somewhere (e.g. in a comment, or somewhere in an import statement), and a
PascalCase
function, the result is that the client code will be injected into the worker. This breaks the worker because that client code contains a reference toHTMLElement
, leading to a very hard to debugUncaught ReferenceError: HTMLElement is not defined
error.This bug appears to be similar in nature to the previously closed #1841
Reproduction
To reproduce it you can use the following code in a file imported as a worker:
There is a full repo example available at https://github.com/Rheeseyb/vite-worker-bug-repro, where the bug can be enabled / disabled by commenting this line
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: