Skip to content

Commit

Permalink
Merge pull request #662 from smapiot/develop
Browse files Browse the repository at this point in the history
Release 1.4.3
  • Loading branch information
FlorianRappl authored Dec 26, 2023
2 parents 420764b + 48dada3 commit 76ceb65
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
65 changes: 34 additions & 31 deletions src/converters/piral-blazor/src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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') {
Expand Down
17 changes: 9 additions & 8 deletions src/converters/piral-blazor/src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function toDepName(url: string) {
return front;
}

const isAssembly = /\.(dll|wasm)$/;

export function createDependencyLoader(convert: ReturnType<typeof createConverter>) {
const definedBlazorReferences: Array<string> = [];
const loadedBlazorPilets: Array<string> = [];
Expand Down Expand Up @@ -81,9 +83,9 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte
}

const supportsCore = capabilities.includes('core-pilet');
const dependencies = references.filter((m) => 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);

Expand All @@ -105,13 +107,13 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte
name: meta.name || '(unknown)',
version: meta.version || '0.0.0',
config: JSON.stringify(meta.config || {}),
baseUrl: meta.basePath || dllUrl.substring(0, dllUrl.lastIndexOf('/')).replace('/_framework/', '/'),
baseUrl: meta.basePath || assemblyUrl.substring(0, assemblyUrl.lastIndexOf('/')).replace('/_framework/', '/'),
dependencies,
dependencySymbols: capabilities.includes('dependency-symbols') ? dependencySymbols : undefined,
sharedDependencies: supportsCore ? sharedDependencies : undefined,
kind: supportsCore ? kind : undefined,
satellites,
dllUrl,
dllUrl: assemblyUrl,
pdbUrl: references.includes(pdbUrl) ? pdbUrl : undefined,
});

Expand All @@ -122,15 +124,14 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte
for (const dllUrl of references) {
const dllName = dllUrl.substring(dllUrl.lastIndexOf('/') + 1);

if (dllUrl.endsWith('.dll')) {
if (isAssembly.test(dllUrl)) {
const entry = loadedDependencies.find((m) => 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);

Expand Down
2 changes: 1 addition & 1 deletion src/converters/piral-blazor/src/interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 76ceb65

Please sign in to comment.