preactjs/wmr

Prerendering throws errors when prerendering a worker

marvinhagemeister opened this issue · 1 comments

Describe the bug
Due to environmental API differences between Web Workers and Node's Worker Threads there are a bunch of undefined global variables that the Web Worker API expects. Things like global Worker in non-worker scripts/modules, global self/addEventListener inside instantiated workers etc.

To Reproduce
Prerender a worker.

Expected behavior
No error.

Bug occurs with:

  • wmr or wmr start (development)
  • wmr build (production) + --prerender
  • wmr serve

We could probably inject self.Worker as a global and point it at web-worker, like we do for location:

globalThis.self = /** @type {any} */ (globalThis);