Skip to content

Commit 1827b75

Browse files
[Blazor WASM] Don't apply hot reload deltas if Blazor has not been initialized (#33122)
1 parent 3eec09e commit 1827b75

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/BuiltInTools/BrowserRefresh/WebSocketScriptInjection.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,25 @@ setTimeout(async function () {
131131
}
132132

133133
let applyFailed = false;
134-
deltas.forEach(d => {
135-
try {
136-
window.Blazor._internal.applyHotReload(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta)
137-
} catch (error) {
138-
console.warn(error);
139-
applyFailed = true;
140-
}
141-
});
134+
if (window.Blazor?._internal?.applyHotReload) {
135+
// Only apply hot reload deltas if Blazor has been initialized.
136+
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
137+
// to be a failure. These deltas will get applied later, when Blazor completes initialization.
138+
deltas.forEach(d => {
139+
try {
140+
window.Blazor._internal.applyHotReload(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta)
141+
} catch (error) {
142+
console.warn(error);
143+
applyFailed = true;
144+
}
145+
});
146+
}
142147

143148
fetch('/_framework/blazor-hotreload', { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify(deltas) })
144149
.then(response => {
145150
if (response.status == 200) {
146151
const etag = response.headers['etag'];
147-
window.sessionStorage.setItem('blazor-webasssembly-cache', { etag, deltas });
152+
window.sessionStorage.setItem('blazor-webassembly-cache', { etag, deltas });
148153
}
149154
});
150155

0 commit comments

Comments
 (0)