[browser][coreCLR] idempotent lazy download of dll/pdb#129666
Open
pavelsavara wants to merge 1 commit into
Open
[browser][coreCLR] idempotent lazy download of dll/pdb#129666pavelsavara wants to merge 1 commit into
pavelsavara wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes browser lazy-assembly loading idempotent by making the loader’s “already loaded” tracking and asset lookup resilient to virtualPath being rewritten during the first fetch (e.g., normalization that prefixes _framework/).
Changes:
- Update lazy assembly/PDB lookup to match by asset filename (basename) instead of full
virtualPath, and track loaded lazy assemblies by the assembly’s basename (without extension). - Add a regression test that loads the same lazy assembly twice and verifies the second call is a no-op (returns
false) and does not throw. - Extend the WASM test asset’s
main.jsto exercise and log the two consecutive lazy-load calls.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/native/libs/Common/JavaScript/loader/assets.ts | Makes lazy assembly/PDB matching and deduplication robust against in-place virtualPath normalization/mutation. |
| src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.cs | Adds regression coverage verifying repeated lazy-load calls are idempotent and don’t surface the “must be marked” error. |
| src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | Adds a test hook to attempt a second lazy load and emit observable results for the new test. |
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.
Summary
Loading the same lazy assembly more than once (e.g. when Blazor fires
OnNavigaterepeatedly) incorrectly threw:
even though the assembly was correctly marked and had already been loaded once.
This change makes a repeated
loadLazyAssemblycall an idempotent no-op thatreturns
false, and adds a regression test.Root cause
The lazy loader matched and de-duplicated assets using the asset's
virtualPathfield. However,
fetchAssemblycallsnormalizeVirtualPath, which mutatesasset.virtualPathin place — it rewrites the.wasmextension to.dllandprefixes the path with the app base (and culture). The
lazyAssemblyresourcesarray holds references to those same asset objects.
As a result, after the first successful load:
virtualPathno longer equals the bareJson.dll/Json.wasmname the lookup compared against, so the second call failed to find the asset.
loadedLazyAssemblies) stored the already-rewritten path, sothe early-return guard never matched on the second call either.
With the asset "not found," the loader fell through to the
must be marked with 'BlazorWebAssemblyLazyLoad'error path.Changes
src/native/libs/Common/JavaScript/loader/assets.tslazyAssetFileName(virtualPath)helper that extracts just thefile name (the segment after the last
/), so asset matching is robust to thein-place normalization that prefixes the path.
rather than the full
virtualPath.assemblyNameWithoutExtensioninstead ofthe mutable
virtualPath, and the dedup check is moved before the assetlookup so a repeated load short-circuits to
return falseimmediately.src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.jsloadLazyAssembly(firstJsonLoad).loadLazyAssemblyTwice=truequery string is set, loads the same lazyassembly a second time and reports
secondJsonLoad, exercising the idempotentpath.
src/mono/wasm/Wasm.Build.Tests/LazyLoadingTests.csLoadLazyAssemblyTwiceIsIdempotent, a regression test that:true,false(idempotent no-op),must be marked with 'BlazorWebAssemblyLazyLoad'error is notemitted to the console.
Testing
Added
LoadLazyAssemblyTwiceIsIdempotenttoWasm.Build.Tests, which reproducesthe failure without the fix and passes with it.