Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use legacy WASM APIs when newer ones are not available #45317

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions src/BuiltInTools/BrowserRefresh/WebSocketScriptInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,12 @@ setTimeout(async function () {
}

let applyError = undefined;
if (window.Blazor?._internal?.applyHotReload) {
// Only apply hot reload deltas if Blazor has been initialized.
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
// to be a failure. These deltas will get applied later, when Blazor completes initialization.
deltas.forEach(d => {
try {
window.Blazor._internal.applyHotReload(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta, d.updatedTypes)
} catch (error) {
console.warn(error);
applyError = error;
}
});

try {
applyDeltas_legacy(deltas)
} catch (error) {
console.warn(error);
applyError = error;
}

try {
Expand All @@ -174,6 +168,24 @@ setTimeout(async function () {
}
}

function applyDeltas_legacy(deltas) {
let apply = window.Blazor?._internal?.applyHotReload

// Only apply hot reload deltas if Blazor has been initialized.
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
// to be a failure. These deltas will get applied later, when Blazor completes initialization.
if (apply) {
deltas.forEach(d => {
if (apply.length == 5) {
// WASM 8.0
apply(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta, d.updatedTypes)
} else {
// WASM 9.0
apply(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta)
}
});
}
}
function sendDeltaApplied() {
connection.send(new Uint8Array([1]).buffer);
}
Expand All @@ -198,11 +210,13 @@ setTimeout(async function () {

let applyError = undefined;
let log = [];
if (window.Blazor?._internal?.applyHotReloadDeltas) {
// Only apply hot reload deltas if Blazor has been initialized.
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
// to be a failure. These deltas will get applied later, when Blazor completes initialization.
try {
try {
let applyDeltas = window.Blazor?._internal?.applyHotReloadDeltas
if (applyDeltas) {
// Only apply hot reload deltas if Blazor has been initialized.
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
// to be a failure. These deltas will get applied later, when Blazor completes initialization.

let wasmDeltas = deltas.map(delta => {
return {
"moduleId": delta.moduleId,
Expand All @@ -213,12 +227,15 @@ setTimeout(async function () {
};
});

log = window.Blazor._internal.applyHotReloadDeltas(wasmDeltas, responseLoggingLevel);
} catch (error) {
console.warn(error);
applyError = error;
log.push({ "message": getMessageAndStack(error), "severity": AgentMessageSeverity_Error });
log = applyDeltas(wasmDeltas, responseLoggingLevel);
} else {
// Try invoke older WASM API:
applyDeltas_legacy(deltas)
}
} catch (error) {
console.warn(error);
applyError = error;
log.push({ "message": getMessageAndStack(error), "severity": AgentMessageSeverity_Error });
}

try {
Expand Down
Loading