Repository navigation
fix: Hot reload edited ESM scripts - #9989
Merged
Merged
Conversation
Public API reportThis PR changes the public API surface (+1 / −1), per the docs' rules (@ignore / @Private / undocumented are excluded). Show API diff-ScriptHandler.load(url: any, callback: any): void
+ScriptHandler.load(url: any, callback: any, asset: any): voidInformational only — this never fails the build. |
Build size reportThis PR changes the size of the minified bundles.
|
Contributor
Author
|
Tested in the Editor with a launched scene. The scene has one entity using an ESM script with a
Not tested: typing in the code editor itself (the edits were saved programmatically), and browsers other than Chrome. |
kpal81xd
marked this pull request as ready for review
November 10, 2026 14:24
kpal81xd
added a commit
that referenced
this pull request
Nov 10, 2026
(cherry picked from commit c4b180f)
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hot reloading with
swapnever worked for ESM (.mjs) scripts. Saving an edited script left the old code running andswapwas never called. Two things stopped it:This PR:
?t=<file hash>only when the file has been edited since then, so the new code runs, re-registers its script types and firesswap.Only the edited file is evaluated again. Modules that import it, or that it imports, keep their existing instances, and its top-level code runs again. Each edit keeps one more module instance in memory until the page reloads. Published builds don't change their files at runtime, so they are unaffected.
Fixes playcanvas/editor#1337
Part of playcanvas/editor#1115
Manual smoke test
swap(old)method and anupdatethat rotates its entity, and attach it to an entity.updateand save.Expected: the launched app rotates at the new speed without a refresh, and
swapis called.Checklist