Skip to content

Commit

Permalink
Compare lazy assemblies without extension during runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jul 12, 2024
1 parent ad088c1 commit f63516c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/mono/browser/runtime/lazyLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,33 @@ export async function loadLazyAssembly (assemblyNameToLoad: string): Promise<boo
throw new Error("No assemblies have been marked as lazy-loadable. Use the 'BlazorWebAssemblyLazyLoad' item group in your project file to enable lazy loading an assembly.");
}

let assemblyNameWithoutExtension = assemblyNameToLoad;
if (assemblyNameToLoad.endsWith(".dll"))
assemblyNameWithoutExtension = assemblyNameToLoad.substring(0, assemblyNameToLoad.length - 4);
else if (assemblyNameToLoad.endsWith(".wasm"))
assemblyNameWithoutExtension = assemblyNameToLoad.substring(0, assemblyNameToLoad.length - 5);

const assemblyNameToLoadDll = assemblyNameWithoutExtension + ".dll";
const assemblyNameToLoadWasm = assemblyNameWithoutExtension + ".wasm";
if (loaderHelpers.config.resources!.fingerprinting) {
const map = loaderHelpers.config.resources!.fingerprinting;
for (const fingerprintedName in map) {
const nonFingerprintedName = map[fingerprintedName];
if (nonFingerprintedName == assemblyNameToLoad) {
if (nonFingerprintedName == assemblyNameToLoadDll || nonFingerprintedName == assemblyNameToLoadWasm) {
assemblyNameToLoad = fingerprintedName;
break;
}
}
}

if (!lazyAssemblies[assemblyNameToLoad]) {
throw new Error(`${assemblyNameToLoad} must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.`);
if (lazyAssemblies[assemblyNameToLoadDll]) {
assemblyNameToLoad = assemblyNameToLoadDll;
} else if (lazyAssemblies[assemblyNameToLoadWasm]) {
assemblyNameToLoad = assemblyNameToLoadWasm;
} else {
throw new Error(`${assemblyNameToLoad} must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.`);
}
}

const dllAsset: AssetEntry = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</ItemGroup>

<ItemGroup>
<BlazorWebAssemblyLazyLoad Include="Json$(WasmAssemblyExtension)" />
<BlazorWebAssemblyLazyLoad Include="Json.dll" />
</ItemGroup>
</Project>

0 comments on commit f63516c

Please sign in to comment.