Fix AssetRegistry URL lookups by type#8842
Conversation
| } | ||
|
|
||
| let result; | ||
| assets.forEach((asset) => { |
There was a problem hiding this comment.
Please replace with a simple for..of loop, with early return inside of it.
mvaligursky
left a comment
There was a problem hiding this comment.
🤖 Automated PR review — posted on my behalf by Claude Code (Opus 4.8). Not a human review; flagging for awareness.
Looks correct and well-tested. Untyped getByUrl(url) preserves the last-added semantics (Set iteration is insertion order, forEach keeps overwriting result), all external callers go through the public method, and the Set-per-url removal is actually more correct than the old map — removing one of two assets sharing a url no longer wipes the other. Nothing blocking. Two minor notes:
-
getByUrliterates the whole set with no early exit and returns the last match. That's intentional to keep untyped compat, but for the typed branch afor...ofwith an earlybreakwould be cheaper and clearer about intent (and would return the first match of that type). Sets are tiny so the perf difference is negligible — purely a readability nit. -
Pre-existing (not introduced here), but now more relevant: the registry indexes by
asset.file.urlataddtime and never re-indexes iffile.urlchanges later (removethen uses the current url, so a changed-url asset leaves a stale set entry). Harmless single-asset before; with multiple assets per url now supported, a stale entry could shadow a live one. Out of scope for this PR — just flagging in case it's worth a follow-up.
Description
Store all assets registered for the same file URL so
AssetRegistry#getByUrl(url, type)can return the asset matching a requested type. UntypedgetByUrl(url)keeps the existing last-added behavior for compatibility.Fixes #8489
Testing
npm test -- test/framework/asset/asset-registry.test.mjs --grep "#getByUrl"npm test -- test/framework/asset/asset-registry.test.mjsnpm run lintnpm run build:typesnpm run test:typesgit diff --checkChecklist