Description
While officially supporting ESM modules, even with top-level await, WebKit doesn't actually implement the module loader spec. This leads to a race condition, where one or more modules fail to load if both of them have a top-level await.
Specification
TC39: https://tc39.es/ecma262/#cyclic-module-record
web-feature
js-modules
Tests
-
A minimal reproducible module, that leads to the race condition when imported twice is this module:
export let bar = 'foo'
await 0
-
@jakearchibald added this repro in the comments below, which seemingly depending on network conditions, fails in Safari when a long enough timeout is used.
-
The language/module-code/top-level-await/fulfillment-order.js test (source) on test262.fyi currently also fails for JavaScriptCore, which at the very least is closely related.
Additional Signals
@shvaikalesh wrote on the stalled WebKit PR:
I don't see any other way except for re-implementing the module loader to adhere to the spec (https://tc39.es/ecma262/#cyclic-module-record), which will take some time.
And @MenloDorian replied with:
This PR requires significant feature-level work to complete. We don't currently have anyone working on it, but we hear the requests and will consider it in our planning.
Motivation
A lot of people using modern frameworks like SvelteKit or Astro (that use native ESM modules) are running into this, and it's often very hard to debug, so they don't realize it's this webkit bug.
Description
While officially supporting ESM modules, even with top-level await, WebKit doesn't actually implement the module loader spec. This leads to a race condition, where one or more modules fail to load if both of them have a top-level await.
Specification
TC39: https://tc39.es/ecma262/#cyclic-module-record
web-feature
js-modules
Tests
A minimal reproducible module, that leads to the race condition when imported twice is this module:
@jakearchibald added this repro in the comments below, which
seemingly depending on network conditions, fails in Safari when a long enough timeout is used.The
language/module-code/top-level-await/fulfillment-order.jstest (source) on test262.fyi currently also fails for JavaScriptCore, which at the very least is closely related.Additional Signals
@shvaikalesh wrote on the stalled WebKit PR:
And @MenloDorian replied with:
Motivation
A lot of people using modern frameworks like SvelteKit or Astro (that use native ESM modules) are running into this, and it's often very hard to debug, so they don't realize it's this webkit bug.