-
Notifications
You must be signed in to change notification settings - Fork 60
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
window is not defined in WebWorkers #163
Comments
Yeah I will fix that, but you will be better moving off barrels files anyway, this slow down most tools: |
So I wanted to add the same support than in the Babel plugin, but I discovered that this is barely working because as soon as you use a hook, the ReactRefresh transformation inject a global call to For anyone that find this, better support in worker requires either:
|
@ArnaudBarre is there a workaround to this window is not defined in WebWorkers? I'm open for patches. |
What causes some HMR code to end-up in your bundle? Most of the time the solution is just to review imports/file split which improve the size of the bundled worker |
I don't get what you mean. Are you talking about separate worker files so that they won't get detected by the plugin => this error won't appear? I actually get them first time running which I think is not a hot reload? |
Most of time the issue happens when you import JSX inside a worker. Is it you case? What file containing HMR code is imported by your worker? |
I'm experimenting with this https://github.com/Shopify/remote-ui/tree/main/examples/kitchen-sink-vite/app/react-worker. It enables rendering JSX inside worker. |
In that case I would recommend to not use any React plugins and let esbuild do the JSX transpilation. This will lead to full reload on every edit but for web workers there is no choice. If using React component inside webworker becames a thing, I hope someone will add HMR support to webworkers instead of having no-op code and bad HMR experience |
thanks for the advice, good one. |
Describe the bug
If you are using Vite with barrel exports, you might end up with situation when you have a barrel file like this:
file: dashboard/index.ts
tsexport * from './helpers' export * from './components'
If there is a web worker (or any other worker) which imports helper from dashboard
tsimport {dashboardHelpers} from './dashboard' // some non-ui related work
Vite will load components anyway (that's how it works now) and there will be ReactRefresh injected code in all of the components codes, which will fail with following error, since there are hard references to window
Uncaught ReferenceError: window is not defined
Exptected:
Plugin should have some checks inside injected code which guards from failing inside non-window contexts
The text was updated successfully, but these errors were encountered: