Open Yukiniro opened 1 month ago
This issue arises because React's Hot Module Replacement (HMR) mechanism automatically inserts helper functions like _s(), which can cause problems when running in a Worker environment. Since the Worker environment is isolated, it cannot access the main thread's context and global variables, leading to errors. Solutions:
Thanks for your suggestion. And I noticed that it can use /* @refresh reset */
for some side effects, so, can we provide something like /* @refresh ignore*/
to avoid injecting code in some scenarios, such as WebGLRenderingContext.useProgram()
?
Yes, introducing a / @refresh ignore / directive to tell the compiler or bundler to avoid injecting code in specific cases (like critical WebGL operations) is a practical and feasible solution. This would help you mark specific functions or sections of code that should not trigger automatic refresh behavior or have code injection. Example Usage: / @refresh ignore / const setupWebGL = () => { const program = gl.createProgram(); gl.linkProgram(program); gl.useProgram(program); // Avoid injecting HMR code here due to potential interference. };
Website or app
https://github.com/Yukiniro/reproduce/tree/master/rspack-issue-hot-update-worker
Repro steps
https://github.com/Yukiniro/reproduce/tree/master/rspack-issue-hot-update-worker
Then, I use the
setup
string to create a worker.There will throw a error in the worker becuase of
_s()
.I am not sure if this is a bug. If not, what could I do sometion to skip the generation of
_s()
.How often does this bug happen?
Every time
DevTools package (automated)
No response
DevTools version (automated)
No response
Error message (automated)
No response
Error call stack (automated)
No response
Error component stack (automated)
No response
GitHub query string (automated)
No response