Skip to content

Commit ce29b66

Browse files
committed
chore: Adjust worker for dotnet.boot.js
1 parent 1f194ca commit ce29b66

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/Uno.Wasm.Bootstrap/Embedded/service-worker.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ if (unoConfig.environmentVariables["UNO_BOOTSTRAP_DEBUGGER_ENABLED"] !== "True")
3333
// existing cached content from the runtime as the keys contain a
3434
// hash we cannot reliably compute.
3535
try {
36-
var c = await import("$(REMOTE_WEBAPP_PATH)_framework/dotnet.boot.js");
37-
// Response validation to catch HTTP errors early
38-
// This prevents trying to parse invalid JSON from error responses
39-
if (!c.ok) {
40-
throw new Error(`Failed to fetch blazor.boot.json: ${c.status} ${c.statusText}`);
36+
// Replace dynamic import with fetch and eval for web worker compatibility
37+
const response = await fetch("$(REMOTE_WEBAPP_PATH)_framework/dotnet.boot.js");
38+
if (!response.ok) {
39+
throw new Error(`Failed to fetch dotnet.boot.js: ${response.status} ${response.statusText}`);
4140
}
4241

43-
const bootJson = await c.default.config;
42+
let scriptContent = await response.text();
43+
44+
const match = scriptContent.match(/.*?\/\*json-start\*\/([\s\S]*?)\/\*json-end\*\//);
45+
46+
// If found, wrap it with parentheses so eval can treat it as an object literal
47+
const c = match ? `(${match[1]})` : null;
48+
49+
if (!c) {
50+
throw `Invalid config`;
51+
}
52+
53+
const bootJson = eval(c);
4454
const monoConfigResources = bootJson.resources || {};
4555

4656
var entries = {

0 commit comments

Comments
 (0)