mirror of
https://github.com/simstudioai/sim.git
synced 2026-10-31 11:54:18 +08:00
`<EnvScript>` defaults to Next's `<Script strategy='beforeInteractive'>`, which does not assign `window.__ENV` — it pushes the assignment onto `self.__next_s`. That queue has one consumer, `appBootstrap`, which reads it once and short-circuits to `hydrate()` when empty. The bootstrap chunk's `<script async>` tag sits ~13KB earlier in the document than the env tag, so when that chunk runs first the queue drains empty, nothing drains it again, and `window.__ENV` stays undefined for the life of the document — every `getEnv` read empty until a reload wins the race. `disableNextScript` emits a plain inline `<script>` that assigns unconditionally, so a lost race costs a few milliseconds instead of the session. Also records whether the assignment was still missing at module-init so the residual (module-scope reads in `env-flags`, which freeze what they see) is measured rather than assumed.