Skip to content

Commit 4d03596

Browse files
authored
Follow-ups to lazy-load from API review (#24169)
* Follow-ups to lazy-load from API review * Address feedback from peer review
1 parent 51739f3 commit 4d03596

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Platform/Mono/MonoPlatform.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,18 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
324324
const assembliesToLoad = BINDING.mono_array_to_js_array<System_String, string>(assembliesToLoadDotNetArray);
325325
const lazyAssemblies = resourceLoader.bootConfig.resources.lazyAssembly;
326326

327-
if (lazyAssemblies) {
328-
const resourcePromises = Promise.all(assembliesToLoad
329-
.filter(assembly => lazyAssemblies.hasOwnProperty(assembly))
327+
if (!lazyAssemblies) {
328+
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.");
329+
}
330+
331+
var assembliesMarkedAsLazy = assembliesToLoad.filter(assembly => lazyAssemblies.hasOwnProperty(assembly));
332+
333+
if (assembliesMarkedAsLazy.length != assembliesToLoad.length) {
334+
var notMarked = assembliesToLoad.filter(assembly => !assembliesMarkedAsLazy.includes(assembly));
335+
throw new Error(`${notMarked.join()} must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.`);
336+
}
337+
338+
const resourcePromises = Promise.all(assembliesMarkedAsLazy
330339
.map(assembly => resourceLoader.loadResource(assembly, `_framework/${assembly}`, lazyAssemblies[assembly], 'assembly'))
331340
.map(async resource => (await resource.response).arrayBuffer()));
332341

@@ -345,8 +354,6 @@ function createEmscriptenModuleInstance(resourceLoader: WebAssemblyResourceLoade
345354
return resourcesToLoad.length;
346355
}));
347356
}
348-
return BINDING.js_to_mono_obj(Promise.resolve(0));
349-
}
350357
});
351358

352359
module.postRun.push(() => {

0 commit comments

Comments
 (0)