diff --git a/src/browser/js/Context.zig b/src/browser/js/Context.zig index 80340552..de24fdb1 100644 --- a/src/browser/js/Context.zig +++ b/src/browser/js/Context.zig @@ -301,9 +301,17 @@ pub fn module(self: *Context, comptime want_result: bool, local: *const js.Local // and the module must have been set after we compiled it lp.assert(entry.module != null, "Context.module with module", .{}); - lp.assert(entry.module_promise == null, "Context.module with module_promise", .{}); - - entry.module_promise = try evaluated.toPromise().persist(); + if (entry.module_promise != null) { + // While loading this script, it's possible that it was dynamically + // included (either the module dynamically loaded itself (unlikely) or + // it included a script which dynamically imported it). If it was, then + // the module_promise would already be setup, and we don't need to do + // anything + } else { + // The *much* more likely case where the module we're trying to load + // didn't [directly or indirectly] dynamically load itself. + entry.module_promise = try evaluated.toPromise().persist(); + } return if (comptime want_result) entry.* else {}; } diff --git a/src/browser/tests/page/module.html b/src/browser/tests/page/module.html index 1dd79794..ed3869a9 100644 --- a/src/browser/tests/page/module.html +++ b/src/browser/tests/page/module.html @@ -58,3 +58,6 @@ testing.expectEqual(true, e.toString().includes("FailedToLoad"), {script_id: 'import-404'}); } + + + diff --git a/src/browser/tests/page/modules/self_async.js b/src/browser/tests/page/modules/self_async.js new file mode 100644 index 00000000..7068c80c --- /dev/null +++ b/src/browser/tests/page/modules/self_async.js @@ -0,0 +1 @@ +const c = await import('./self_async.js');