Skip to content

Commit 117a449

Browse files
fix(defer): propagate a rejected async dependency to every importer
A rejected async module still sets its done flag, so a later deferred import of the same subgraph read it as finished and never awaited it, dropping the error. It is now awaited whenever it carries one. The old check read the flag from the module record, where it is never set, so it meant "not yet required" and hid this behind the first importer; rewriting it for the evaluation-order fix made it reachable from the predicate itself.
1 parent 1b617c2 commit 117a449

7 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎lib/runtime/AsyncModuleRuntimeModule.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
5757
`${cst} hasUnresolvedAsyncSubgraph = asyncDeps.some((id) => {`,
5858
Template.indent([
5959
`${cst} cache = __webpack_module_cache__[id];`,
60+
"if (!cache) return true;",
6061
// The deferred import starts these, so a cache entry no
61-
// longer means the async body has finished.
62-
"return !cache || cache.exports[webpackDone] !== true;"
62+
// longer means the body finished; a rejected one is
63+
// "done" but its error still has to reach the importer.
64+
`${cst} deps = cache.exports;`,
65+
"return deps[webpackDone] !== true || deps[webpackError] !== undefined;"
6366
]),
6467
"});",
6568
"if (hasUnresolvedAsyncSubgraph) {",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
await Promise.resolve();
2+
throw new Error("boom");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./boom.js";
2+
export const value = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import defer * as ns from "./dep.js";
2+
export const tag = "first";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// A rejected async dependency is "done", so its error must still reach every
2+
// deferred import of the same subgraph, not just the one that started it.
3+
it("should reject every importer of a failed deferred async dependency", async () => {
4+
await expect(import("./first.js")).rejects.toThrow("boom");
5+
await expect(import("./second.js")).rejects.toThrow("boom");
6+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import defer * as ns from "./dep.js";
2+
export const tag = "second";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
experiments: {
6+
deferImport: true,
7+
topLevelAwait: true
8+
}
9+
};

0 commit comments

Comments
 (0)