Skip to content

fix(preview): avoid stale script chunks when the pack is rebuilt out-of-band#728

Open
bofeng-song wants to merge 1 commit into
cocos:mainfrom
bofeng-song:fix/preview-chunk-404-pack-hot-reload
Open

fix(preview): avoid stale script chunks when the pack is rebuilt out-of-band#728
bofeng-song wants to merge 1 commit into
cocos:mainfrom
bofeng-song:fix/preview-chunk-404-pack-hot-reload

Conversation

@bofeng-song

Copy link
Copy Markdown
Contributor

Problem

When Cocos Creator and the cli-driven IDE open the same project at the same time, both share <project>/temp/programming/packer-driver. Editing and saving a script that the scene references makes Creator recompile out-of-band, mutating that shared pack store (new chunk hashes, old chunks removed). Opening/refreshing the cli preview then fails with high probability:

Error: Error loading .../chunks/dc/dc7a08...js from .../chunks/6d/6d8fd2...js (SystemJS Error#3)

i.e. a loaded chunk imports a chunk hash that no longer exists (404). Two causes:

  1. the cli's in-memory QuickPackLoader still holds the previous import-map (it doesn't know another process recompiled), and
  2. pack chunks are served without cache headers, so the browser keeps a stale chunk whose baked import points to a removed hash.

Changes

  • scripting-routes: serve pack resources (/scripting/x, /chunks) with Cache-Control: no-store, so the browser never keeps a stale chunk or import-map.
  • live-reload: watch temp/programming/packer-driver; when import-map.json / resolution-detail-map.json change (a compile finished — possibly in another process such as Creator), refresh the in-memory loader via facet.notifyPackDriverUpdated() and trigger a browser reload, so the preview always loads a consistent import-map + chunks.

Notes

Test

  • With Creator + cli on the same project: edit a referenced script, save, open the cli preview — no more SystemJS chunk 404.

…of-band

When Creator and the cli-driven IDE open the same project, they share
<project>/temp/programming/packer-driver. Creator recompiling on save mutates that
shared store (new chunk hashes, old chunks removed); the cli then serves a stale
in-memory import-map / browser-cached chunk that references a removed chunk hash,
so the preview fails with SystemJS Error#3 (chunk 404).

- scripting-routes: serve pack resources (/scripting/x, /chunks) with
  Cache-Control: no-store so the browser never keeps a stale chunk / import-map.
- live-reload: watch temp/programming/packer-driver; when import-map /
  resolution-detail-map change (a compile finished, possibly in another process),
  refresh the in-memory QuickPackLoader (facet.notifyPackDriverUpdated) and trigger
  a browser reload, so the preview loads a consistent import-map + chunks.
@bofeng-song bofeng-song added the pending Not ready yet label Jul 13, 2026
@star-e star-e added wontfix This will not be worked on and removed pending Not ready yet labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants