diff --git a/CHANGELOG.md b/CHANGELOG.md index 796477368..8b9373ffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Piral Changelog +## 1.4.3 (tbd) + +- Fixed issue with `piral-blazor` using routing in standalone mode +- Fixed issue with `piral-blazor` connecting the Piral events +- Fixed support of `piral-blazor` for .NET 8 Blazor + ## 1.4.2 (December 16, 2023) - Fixed misplaced *index.d.ts* in a scaffolded pilet (#658) diff --git a/src/converters/piral-blazor/src/converter.ts b/src/converters/piral-blazor/src/converter.ts index 6cda1d692..e384c511c 100644 --- a/src/converters/piral-blazor/src/converter.ts +++ b/src/converters/piral-blazor/src/converter.ts @@ -87,32 +87,32 @@ export function createConverter( } } + if (capabilities.includes('events')) { + const eventDispatcher = document.body.dispatchEvent; + + // listen to all events for forwarding them + document.body.dispatchEvent = function (ev: CustomEvent) { + if (ev.type.startsWith('piral-')) { + const type = ev.type.replace('piral-', ''); + const args = ev.detail.arg; + + try { + JSON.stringify(args); + processEvent(type, args); + } catch { + console.warn(`The event "${type}" could not be serialized and will not be handled by Blazor.`); + } + } + + return eventDispatcher.call(this, ev); + }; + } + if (language && capabilities.includes('language')) { if (typeof language.current === 'string') { await setLanguage(language.current); } - if (capabilities.includes('events')) { - const eventDispatcher = document.body.dispatchEvent; - - // listen to all events for forwarding them - document.body.dispatchEvent = function (ev: CustomEvent) { - if (ev.type.startsWith('piral-')) { - const type = ev.type.replace('piral-', ''); - const args = ev.detail.arg; - - try { - JSON.stringify(args); - processEvent(type, args); - } catch { - console.warn(`The event "${type}" could not be serialized and will not be handled by Blazor.`); - } - } - - return eventDispatcher.call(this, ev); - }; - } - if (typeof language.onChange === 'function') { language.onChange(setLanguage); } @@ -148,16 +148,6 @@ export function createConverter( addGlobalEventListeners(el); - if (listener === undefined) { - listener = nav.listen(({ location, action }) => { - // POP is already handled by .NET - if (action !== 'POP') { - const url = makeUrl(location.href); - callNotifyLocationChanged(url, action === 'REPLACE', location.state); - } - }); - } - locals.state = 'fresh'; locals.next = noop; locals.dispose = attachEvents( @@ -217,6 +207,19 @@ export function createConverter( } (loader || (convert.loader = loader = boot(opts))) + .then((config) => { + if (listener === undefined) { + listener = nav.listen(({ location, action }) => { + // POP is already handled by .NET + if (action !== 'POP') { + const url = makeUrl(location.href); + callNotifyLocationChanged(url, action === 'REPLACE', location.state); + } + }); + } + + return config; + }) .then((config) => dependency(config).then(() => { if (locals.state === 'fresh') { diff --git a/src/converters/piral-blazor/src/dependencies.ts b/src/converters/piral-blazor/src/dependencies.ts index cae9ba6c5..c6da4b940 100644 --- a/src/converters/piral-blazor/src/dependencies.ts +++ b/src/converters/piral-blazor/src/dependencies.ts @@ -32,6 +32,8 @@ function toDepName(url: string) { return front; } +const isAssembly = /\.(dll|wasm)$/; + export function createDependencyLoader(convert: ReturnType) { const definedBlazorReferences: Array = []; const loadedBlazorPilets: Array = []; @@ -81,9 +83,9 @@ export function createDependencyLoader(convert: ReturnType m.endsWith('.dll')); - const dllUrl = dependencies.pop(); - const pdbUrl = toPdb(dllUrl); + const dependencies = references.filter((m) => isAssembly.test(m)); + const assemblyUrl = dependencies.pop(); + const pdbUrl = toPdb(assemblyUrl); const dependencySymbols = dependencies.map(toPdb).filter((dep) => references.includes(dep)); const id = Math.random().toString(26).substring(2); @@ -105,13 +107,13 @@ export function createDependencyLoader(convert: ReturnType m.name === dllName); if (entry) { entry.count++; await entry.promise; } else { - const urlWithoutExtension = dllUrl.substring(0, dllUrl.length - 4); - const pdbName = `${urlWithoutExtension}.pdb`; + const pdbName = toPdb(dllUrl); const pdbUrl = references.find((m) => m === pdbName); const promise = pdbUrl ? loadResourceWithSymbol(dllUrl, pdbUrl) : loadResource(dllUrl); diff --git a/src/converters/piral-blazor/src/interop.ts b/src/converters/piral-blazor/src/interop.ts index 1ba901480..b76dbf27d 100644 --- a/src/converters/piral-blazor/src/interop.ts +++ b/src/converters/piral-blazor/src/interop.ts @@ -6,7 +6,7 @@ const wasmLib = 'Microsoft.AspNetCore.Components.WebAssembly'; const coreLib = 'Piral.Blazor.Core'; function isDotNet6OrBelow() { - return typeof window.Blazor._internal.NavigationLock === 'undefined'; + return typeof window.Blazor?._internal?.NavigationLock === 'undefined'; } function createBase() {