You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(core): break ecs/world ↔ in it/world-initializer import cycle
Summary:
After D105972540 introduced a narrow `sideEffects` allowlist in `iwsdk/core`'s `package.json`, the bundler stopped eliding side-effect-only imports and started honoring the full module graph during code emission. That exposed a latent value-level import cycle:
ecs/world.ts → init/index.js (barrel) → init/world-initializer.ts → ecs/index.js → ecs/world.ts
Because `createSystem({queries: {required: [X]}})` captures the component reference `X` at class-body evaluation time, this cycle let bundlers (Vite/esbuild prebundle and the production Rollup bundle) emit `AudioSystem`'s class body before `AudioSource` was defined. The query then held `[undefined]`, and the failure surfaced later at `QueryManager.registerQuery` with `Cannot read properties of undefined (reading 'bitmask')`.
Three changes break the cycle and prevent regressions:
1. `ecs/world.ts` no longer imports `initializeWorld` statically — it `await import()`s `init/world-initializer.js` from inside `World.create()`. `WorldOptions` is now a `type` import (erased at build time). `launchXR` and `XROptions` come directly from `init/xr.js`, bypassing the `init/index.js` barrel.
2. `audio/audio-system.ts` and `audio/audio.ts` import `Types`, `Entity`, `createSystem`, and `createComponent` directly from `ecs/{component,entity,system}.js` rather than the `ecs/index.js` barrel. Defense-in-depth: even if a future change reintroduces a `world.ts`-side cycle, these modules will no longer participate in it.
3. New `tests/ecs/no-import-cycles.test.ts` asserts that `AudioSystem.queries.audioEntities.required[0]` is `AudioSource` (not `undefined`) at import time. This is a fast TDZ regression guard — if a future bundler change reintroduces the load-order bug, this test fails before any consumer crashes.
Reviewed By: cabanier
Differential Revision: D106196204
fbshipit-source-id: 1e6b227213d5393161f9f4ce9d962353edcefbbd
0 commit comments