fix(loader): unloadAll threw on fontfaces and never freed videos#1535
Merged
Conversation
Three long-latent bugs in the unload path, surfaced by #1534's pre-merge review: - unloadAll's video-cache sweep dispatched entries as type "json" (copy- paste from the loop above), so the jsonList lookup missed and video assets survived every unloadAll. - unloadAll's font-cache sweep used type "font" — an unknown type that hit unload()'s default throw, ABORTING the whole unloadAll mid-way (obj/mtl/ gltf/shader/audio sweeps never ran) whenever any fontface was loaded. (Its comment also said "video resources" — same copy-paste.) - The fontface unload case guarded on `typeof typeof globalThis.document` — always "string", never "undefined" — so the DOM check was inert. Regression test seeds videoList + fontList (real FontFace) and asserts unloadAll doesn't throw and empties both — verified to FAIL against the old code and pass with the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019t8kP8vp58ZrvaD2FqJU6A
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes three long-standing issues in the loader unload path so loader.unloadAll() reliably cleans up video and fontface assets without throwing, and documents the fix in the changelog. This aligns the loader’s cache-sweep behavior with the supported unload() asset types and prevents unloadAll() from aborting early due to an invalid type.
Changes:
- Correct
unloadAll()dispatch types forvideoList("video") andfontList("fontface"), preventing missed unloads and avoiding the default throw path. - Fix an always-true DOM guard in the
"fontface"unload case (typeof typeof ...→typeof ...). - Add a regression test that seeds
videoList+fontListand assertsunloadAll()doesn’t throw and clears both.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/melonjs/tests/loader.spec.js | Adds regression test covering unloadAll() behavior for video + fontface caches. |
| packages/melonjs/src/loader/loader.js | Fixes fontface DOM guard and corrects unloadAll() type routing for video/fontface cache sweeps. |
| packages/melonjs/CHANGELOG.md | Documents the unloadAll() fontface/video unload fixes and the DOM guard correction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Three long-latent bugs in the loader's unload path, surfaced by the pre-merge review of #1534 (out of scope there, fixed here):
unloadAllnever freed videos — the video-cache sweep dispatched entries astype: "json"(copy-paste from the json loop above it), so the lookup missed and video assets survived everyunloadAll.unloadAllthrew if any fontface was loaded — the font-cache sweep usedtype: "font", an unknown type that hitsunload()'s defaultthrow, aborting the wholeunloadAllmid-way (the obj / mtl / gltf / shader / audio sweeps never ran). Its comment also said "video resources" — same copy-paste origin.typeof typeof globalThis.document !== "undefined";typeof typeof xis always"string", so the guard was permanently true.Test
Regression test seeds
videoList+fontList(with a realFontFace) and assertsunloadAll()doesn't throw and empties both caches — verified to fail against the old code (revert-check) and pass with the fix.Full suite 4565 passed / 0 failed; eslint + tsc + biome clean.
🤖 Generated with Claude Code