Skip to content

Commit c3cf34b

Browse files
authored
Calculate fetchBase once at toplevel
> It's important to note that this will not reference the <script> element if the code in the script is being called as a callback or event handler; it will only reference the element while it's initially being processed. https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript Base was applied to the first wasm file, but not to subsequent files. This is an issue if you're loading a page at /foo/bar/baz and have your wasm hosted at /client.bc.wasm.assets, only appears in separate compilation.
1 parent 090b7b2 commit c3cf34b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

runtime/wasm/runtime.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@
471471
const f = path.join(path.dirname(require.main.filename), src);
472472
return require("node:fs/promises").readFile(f);
473473
}
474+
const fetchBase = globalThis?.document?.currentScript?.src;
474475
function fetchRelative(src) {
475-
const base = globalThis?.document?.currentScript?.src;
476-
const url = base ? new URL(src, base) : src;
476+
const url = fetchBase ? new URL(src, fetchBase) : src;
477477
return fetch(url);
478478
}
479479
const loadCode = isNode ? loadRelative : fetchRelative;

0 commit comments

Comments
 (0)