jpywtora
(John Pywtorak)
August 27, 2025, 3:34pm
1
Vaadin 24.7.10 Flow+Hilla
Reference to window
is undefined error.
What it appears to be is the Vaadin widget in the bottom right, connection, related, which is unfortunate.
SEE:
vaadin:main
← vaadin:fix/sw-context-adjustments
opened 04:18PM - 11 Nov 24 UTC
Adjust the library to be used in the Service Worker context without DOM global v… ariables
Fixes https://github.com/vaadin/hilla/issues/2867
Pull request seems to be exactly related. Also the Connextion Indicator?
PWA / service worker support improvements · Issue #2814 · vaadin/hilla · GitHub open issue still.
it says service worker, but it is the same issue for a regular worker.
opened 09:16AM - 24 Oct 24 UTC
closed 02:49PM - 25 Nov 24 UTC
bug
hilla
prerelease version for Hilla 24.6.0
Released with Hilla 24.6.0.beta2
prerelease version for Hilla 24.8.0
Released with Hilla 24.8.0.alpha5
### Describe the bug
Some issues stop endpoints from being called from the Serv… ice Worker.
Most of the issues are that `window` or `document` references are not available in the worker context.
Which should be quite easy to solve:
- https://github.com/vaadin/hilla/blob/c7d4707995f2235574f48d84a8619ab038beb503/packages/ts/frontend/src/Connect.ts#L21
- https://github.com/vaadin/hilla/blob/c7d4707995f2235574f48d84a8619ab038beb503/packages/ts/frontend/src/Connect.ts#L303
- https://github.com/vaadin/hilla/blob/c7d4707995f2235574f48d84a8619ab038beb503/packages/ts/frontend/src/CookieManager.ts#L8
Then there are related to the same issue but more complicated issues:
1. `__REGISTER__()` includes references to `window` - but is defined in a different place
https://github.com/vaadin/hilla/blob/c7d4707995f2235574f48d84a8619ab038beb503/packages/ts/frontend/src/index.ts#L8C1-L8C16
2. `ConnectionState` and `ConnectionIndicator `from `@vaadin/common-frontend` also have references to `window` and need to be either fixed in their repo or clone+fixed in hilla separately
https://github.com/vaadin/hilla/blob/c7d4707995f2235574f48d84a8619ab038beb503/packages/ts/frontend/src/Connect.ts#L2
3. Lastly there is an issue with atmosphere.js and default exports to Vite. Atmosphere dependency could be excluded by SW Vite plugin or by finding a better fix for exclusion as I am not sure about this approach.
> RollupError: node_modules/@vaadin/hilla-frontend/FluxConnection.js (1:7): "default" is not exported by "node_modules/atmosphere.js/lib/browser.js", imported by "node_modules/@vaadin/hilla-frontend/FluxConnection.js".
> at getRollupError (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:396:41)
> at error (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:392:42)
> at Module.error (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:13858:16)
> at Module.traceVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:14306:29)
> at ModuleScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:11984:39)
> at ChildScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
> at ClassBodyScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
> at ChildScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
> at ChildScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
> at FunctionScope.findVariable (file:///app/node_modules/rollup/dist/es/shared/node-entry.js:7432:38)
Missing CSRF token in calling endpoints is separated in an another issue: #2791
### Expected-behavior
All DOM `window` or `document` references should be prefixed with `self.window && window...` or `self.document && document...` (or some alternative) so that SW could run without encountering them.
### Reproduction
[sw-app.zip](https://github.com/user-attachments/files/17504344/sw-app.zip)
### System Info
Hilla 24.5
Another issue but closed, not to me and what I am seeing.
Leif
(Leif Åstrand)
August 27, 2025, 7:05pm
2
Those changes were introduced in version 24.8 so you will have to upgrade. The changes were mainly intended for Service Workers. I don’t remember if we also tested with regular Workers but the same changes should at least in theory apply for both environments.