Repository: vercel/next.js
Pull request: Turbopack: load chunks only once



Closes PACK-4352

Changed files:
filename: turbopack/crates/turbopack-ecmascript-runtime/js/src/browser/runtime/dom/runtime-backend-dom.ts
patch: @@ -12,9 +12,10 @@
 
 type ChunkResolver = {
   resolved: boolean;
+  loadingStarted: boolean;
   resolve: () => void;
   reject: (error?: Error) => void;
-  promise: Promise<void>;
+  promise: Promise<any>;
 };
 
 let BACKEND: RuntimeBackend;
@@ -107,6 +108,7 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map();
       });
       resolver = {
         resolved: false,
+        loadingStarted: false,
         promise,
         resolve: () => {
           resolver!.resolved = true;
@@ -125,13 +127,14 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map();
     */
   function doLoadChunk(chunkUrl: ChunkUrl, source: SourceInfo) {
     const resolver = getOrCreateResolver(chunkUrl);
-    if (resolver.resolved) {
+    if (resolver.loadingStarted) {
       return resolver.promise;
     }
 
     if (source.type === SourceType.Runtime) {
       // We don't need to load chunks references from runtime code, as they're already
       // present in the DOM.
+      resolver.loadingStarted = true;
 
       if (isCss(chunkUrl)) {
         // CSS chunks do not register themselves, and as such must be marked as
@@ -210,6 +213,7 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map();
       }
     }
 
+    resolver.loadingStarted = true;
     return resolver.promise;
   }
 

filename: turbopack/crates/turbopack-ecmascript-runtime/js/src/nodejs/runtime.ts
patch: @@ -95,13 +95,19 @@ function loadChunk(chunkData: ChunkData, source?: SourceInfo): void {
   }
 }
 
+const loadedChunks = new Set<ChunkPath>();
+
 function loadChunkPath(chunkPath: ChunkPath, source?: SourceInfo): void {
   if (!isJs(chunkPath)) {
     // We only support loading JS chunks in Node.js.
     // This branch can be hit when trying to load a CSS chunk.
     return;
   }
 
+  if (loadedChunks.has(chunkPath)) {
+    return;
+  }
+
   try {
     const resolved = path.resolve(RUNTIME_ROOT, chunkPath);
     const chunkModules: ModuleFactories = require(resolved);
@@ -111,6 +117,7 @@ function loadChunkPath(chunkPath: ChunkPath, source?: SourceInfo): void {
         moduleFactories[moduleId] = moduleFactory;
       }
     }
+    loadedChunks.add(chunkPath);
   } catch (e) {
     let errorMessage = `Failed to load chunk ${chunkPath}`;
 
@@ -135,6 +142,10 @@ async function loadChunkAsync(
     return;
   }
 
+  if (loadedChunks.has(chunkPath)) {
+    return;
+  }
+
   const resolved = path.resolve(RUNTIME_ROOT, chunkPath);
 
   try {
@@ -162,6 +173,7 @@ async function loadChunkAsync(
         moduleFactories[moduleId] = moduleFactory;
       }
     }
+    loadedChunks.add(chunkPath);
   } catch (e) {
     let errorMessage = `Failed to load chunk ${chunkPath}`;
 

filename: turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js
patch: @@ -465,12 +465,16 @@ function loadChunk(chunkData, source) {
         return loadChunkPath(chunkData.path, source);
     }
 }
+const loadedChunks = new Set();
 function loadChunkPath(chunkPath, source) {
     if (!isJs(chunkPath)) {
         // We only support loading JS chunks in Node.js.
         // This branch can be hit when trying to load a CSS chunk.
         return;
     }
+    if (loadedChunks.has(chunkPath)) {
+        return;
+    }
     try {
         const resolved = path.resolve(RUNTIME_ROOT, chunkPath);
         const chunkModules = require(resolved);
@@ -479,6 +483,7 @@ function loadChunkPath(chunkPath, source) {
                 moduleFactories[moduleId] = moduleFactory;
             }
         }
+        loadedChunks.add(chunkPath);
     } catch (e) {
         let errorMessage = `Failed to load chunk ${chunkPath}`;
         if (source) {
@@ -496,6 +501,9 @@ async function loadChunkAsync(source, chunkData) {
         // This branch can be hit when trying to load a CSS chunk.
         return;
     }
+    if (loadedChunks.has(chunkPath)) {
+        return;
+    }
     const resolved = path.resolve(RUNTIME_ROOT, chunkPath);
     try {
         const contents = await fs.readFile(resolved, "utf-8");
@@ -519,6 +527,7 @@ async function loadChunkAsync(source, chunkData) {
                 moduleFactories[moduleId] = moduleFactory;
             }
         }
+        loadedChunks.add(chunkPath);
     } catch (e) {
         let errorMessage = `Failed to load chunk ${chunkPath}`;
         if (source) {

filename: turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js.map
patch: @@ -6,5 +6,5 @@
     {"offset": {"line": 337, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared-node/base-externals-utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/// <reference path=\"../shared/runtime-utils.ts\" />\n\n/// A 'base' utilities to support runtime can have externals.\n/// Currently this is for node.js / edge runtime both.\n/// If a fn requires node.js specific behavior, it should be placed in `node-external-utils` instead.\n\nasync function externalImport(id: ModuleId) {\n  let raw\n  try {\n    raw = await import(id)\n  } catch (err) {\n    // TODO(alexkirsz) This can happen when a client-side module tries to load\n    // an external module we don't provide a shim for (e.g. querystring, url).\n    // For now, we fail semi-silently, but in the future this should be a\n    // compilation error.\n    throw new Error(`Failed to load external module ${id}: ${err}`)\n  }\n\n  if (raw && raw.__esModule && raw.default && 'default' in raw.default) {\n    return interopEsm(raw.default, createNS(raw), true)\n  }\n\n  return raw\n}\n\nfunction externalRequire(\n  id: ModuleId,\n  thunk: () => any,\n  esm: boolean = false\n): Exports | EsmNamespaceObject {\n  let raw\n  try {\n    raw = thunk()\n  } catch (err) {\n    // TODO(alexkirsz) This can happen when a client-side module tries to load\n    // an external module we don't provide a shim for (e.g. querystring, url).\n    // For now, we fail semi-silently, but in the future this should be a\n    // compilation error.\n    throw new Error(`Failed to load external module ${id}: ${err}`)\n  }\n\n  if (!esm || raw.__esModule) {\n    return raw\n  }\n\n  return interopEsm(raw, createNS(raw), true)\n}\n\nexternalRequire.resolve = (\n  id: string,\n  options?: {\n    paths?: string[]\n  }\n) => {\n  return require.resolve(id, options)\n}\n"],"names":[],"mappings":"AAAA,oDAAoD,GAEpD,mDAAmD;AAEnD,6DAA6D;AAC7D,sDAAsD;AACtD,qGAAqG;AAErG,eAAe,eAAe,EAAY;IACxC,IAAI;IACJ,IAAI;QACF,MAAM,MAAM,MAAM,CAAC;IACrB,EAAE,OAAO,KAAK;QACZ,0EAA0E;QAC1E,0EAA0E;QAC1E,qEAAqE;QACrE,qBAAqB;QACrB,MAAM,IAAI,MAAM,CAAC,+BAA+B,EAAE,GAAG,EAAE,EAAE,KAAK;IAChE;IAEA,IAAI,OAAO,IAAI,UAAU,IAAI,IAAI,OAAO,IAAI,aAAa,IAAI,OAAO,EAAE;QACpE,OAAO,WAAW,IAAI,OAAO,EAAE,SAAS,MAAM;IAChD;IAEA,OAAO;AACT;AAEA,SAAS,gBACP,EAAY,EACZ,KAAgB,EAChB,MAAe,KAAK;IAEpB,IAAI;IACJ,IAAI;QACF,MAAM;IACR,EAAE,OAAO,KAAK;QACZ,0EAA0E;QAC1E,0EAA0E;QAC1E,qEAAqE;QACrE,qBAAqB;QACrB,MAAM,IAAI,MAAM,CAAC,+BAA+B,EAAE,GAAG,EAAE,EAAE,KAAK;IAChE;IAEA,IAAI,CAAC,OAAO,IAAI,UAAU,EAAE;QAC1B,OAAO;IACT;IAEA,OAAO,WAAW,KAAK,SAAS,MAAM;AACxC;AAEA,gBAAgB,OAAO,GAAG,CACxB,IACA;IAIA,OAAO,QAAQ,OAAO,CAAC,IAAI;AAC7B","ignoreList":[0]}},
     {"offset": {"line": 376, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared-node/node-externals-utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\ndeclare var RUNTIME_PUBLIC_PATH: string;\ndeclare var RELATIVE_ROOT_PATH: string;\ndeclare var ASSET_PREFIX: string;\n\nconst path = require(\"path\");\n\nconst relativePathToRuntimeRoot = path.relative(RUNTIME_PUBLIC_PATH, \".\");\n// Compute the relative path to the `distDir`.\nconst relativePathToDistRoot = path.join(\n  relativePathToRuntimeRoot,\n  RELATIVE_ROOT_PATH\n);\nconst RUNTIME_ROOT = path.resolve(__filename, relativePathToRuntimeRoot);\n// Compute the absolute path to the root, by stripping distDir from the absolute path to this file.\nconst ABSOLUTE_ROOT = path.resolve(__filename, relativePathToDistRoot);\n\n/**\n * Returns an absolute path to the given module path.\n * Module path should be relative, either path to a file or a directory.\n *\n * This fn allows to calculate an absolute path for some global static values, such as\n * `__dirname` or `import.meta.url` that Turbopack will not embeds in compile time.\n * See ImportMetaBinding::code_generation for the usage.\n */\nfunction resolveAbsolutePath(modulePath?: string): string {\n  if (modulePath) {\n    return path.join(ABSOLUTE_ROOT, modulePath);\n  }\n  return ABSOLUTE_ROOT;\n}\n"],"names":[],"mappings":"AAAA,oDAAoD,GAMpD,MAAM,OAAO,QAAQ;AAErB,MAAM,4BAA4B,KAAK,QAAQ,CAAC,qBAAqB;AACrE,8CAA8C;AAC9C,MAAM,yBAAyB,KAAK,IAAI,CACtC,2BACA;AAEF,MAAM,eAAe,KAAK,OAAO,CAAC,YAAY;AAC9C,mGAAmG;AACnG,MAAM,gBAAgB,KAAK,OAAO,CAAC,YAAY;AAE/C;;;;;;;CAOC,GACD,SAAS,oBAAoB,UAAmB;IAC9C,IAAI,YAAY;QACd,OAAO,KAAK,IAAI,CAAC,eAAe;IAClC;IACA,OAAO;AACT","ignoreList":[0]}},
     {"offset": {"line": 396, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared-node/node-wasm-utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/// <reference path=\"../shared/runtime-utils.ts\" />\n\nfunction readWebAssemblyAsResponse(path: string) {\n  const { createReadStream } = require(\"fs\") as typeof import(\"fs\");\n  const { Readable } = require(\"stream\") as typeof import(\"stream\");\n\n  const stream = createReadStream(path);\n\n  // @ts-ignore unfortunately there's a slight type mismatch with the stream.\n  return new Response(Readable.toWeb(stream), {\n    headers: {\n      \"content-type\": \"application/wasm\",\n    },\n  });\n}\n\nasync function compileWebAssemblyFromPath(\n  path: string\n): Promise<WebAssembly.Module> {\n  const response = readWebAssemblyAsResponse(path);\n\n  return await WebAssembly.compileStreaming(response);\n}\n\nasync function instantiateWebAssemblyFromPath(\n  path: string,\n  importsObj: WebAssembly.Imports\n): Promise<Exports> {\n  const response = readWebAssemblyAsResponse(path);\n\n  const { instance } = await WebAssembly.instantiateStreaming(\n    response,\n    importsObj\n  );\n\n  return instance.exports;\n}\n"],"names":[],"mappings":"AAAA,oDAAoD,GAEpD,mDAAmD;AAEnD,SAAS,0BAA0B,IAAY;IAC7C,MAAM,EAAE,gBAAgB,EAAE,GAAG,QAAQ;IACrC,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ;IAE7B,MAAM,SAAS,iBAAiB;IAEhC,2EAA2E;IAC3E,OAAO,IAAI,SAAS,SAAS,KAAK,CAAC,SAAS;QAC1C,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,eAAe,2BACb,IAAY;IAEZ,MAAM,WAAW,0BAA0B;IAE3C,OAAO,MAAM,YAAY,gBAAgB,CAAC;AAC5C;AAEA,eAAe,+BACb,IAAY,EACZ,UAA+B;IAE/B,MAAM,WAAW,0BAA0B;IAE3C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,YAAY,oBAAoB,CACzD,UACA;IAGF,OAAO,SAAS,OAAO;AACzB","ignoreList":[0]}},
-    {"offset": {"line": 417, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/nodejs/runtime.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/// <reference path=\"../shared/runtime-utils.ts\" />\n/// <reference path=\"../shared-node/base-externals-utils.ts\" />\n/// <reference path=\"../shared-node/node-externals-utils.ts\" />\n/// <reference path=\"../shared-node/node-wasm-utils.ts\" />\n\nenum SourceType {\n  /**\n   * The module was instantiated because it was included in an evaluated chunk's\n   * runtime.\n   */\n  Runtime = 0,\n  /**\n   * The module was instantiated because a parent module imported it.\n   */\n  Parent = 1,\n}\n\ntype SourceInfo =\n  | {\n      type: SourceType.Runtime;\n      chunkPath: ChunkPath;\n    }\n  | {\n      type: SourceType.Parent;\n      parentId: ModuleId;\n    };\n\nprocess.env.TURBOPACK = '1';\n\nfunction stringifySourceInfo(source: SourceInfo): string {\n  switch (source.type) {\n    case SourceType.Runtime:\n      return `runtime for chunk ${source.chunkPath}`;\n    case SourceType.Parent:\n      return `parent module ${source.parentId}`;\n    default:\n      invariant(source, (source) => `Unknown source type: ${source?.type}`);\n  }\n}\n\ntype ExternalRequire = (\n  id: ModuleId,\n  thunk: () => any,\n  esm?: boolean\n) => Exports | EsmNamespaceObject;\ntype ExternalImport = (id: ModuleId) => Promise<Exports | EsmNamespaceObject>;\n\ninterface TurbopackNodeBuildContext extends TurbopackBaseContext<Module> {\n  R: ResolvePathFromModule;\n  x: ExternalRequire;\n  y: ExternalImport;\n}\n\ntype ModuleFactory = (\n  this: Module[\"exports\"],\n  context: TurbopackNodeBuildContext\n) => undefined;\n\nconst url = require(\"url\") as typeof import('url');\nconst fs = require(\"fs/promises\") as typeof import('fs/promises');\n\nconst moduleFactories: ModuleFactories = Object.create(null);\nconst moduleCache: ModuleCache<ModuleWithDirection> = Object.create(null);\n\n/**\n * Returns an absolute path to the given module's id.\n */\nfunction createResolvePathFromModule(\n  resolver: (moduleId: string) => Exports\n): (moduleId: string) => string {\n  return function resolvePathFromModule(moduleId: string): string {\n    const exported = resolver(moduleId);\n    const exportedPath = exported?.default ?? exported;\n    if (typeof exportedPath !== \"string\") {\n      return exported as any;\n    }\n\n    const strippedAssetPrefix = exportedPath.slice(ASSET_PREFIX.length);\n    const resolved = path.resolve(\n      RUNTIME_ROOT,\n      strippedAssetPrefix\n    );\n\n    return url.pathToFileURL(resolved).href;\n  };\n}\n\nfunction loadChunk(chunkData: ChunkData, source?: SourceInfo): void {\n  if (typeof chunkData === \"string\") {\n    return loadChunkPath(chunkData, source);\n  } else {\n    return loadChunkPath(chunkData.path, source);\n  }\n}\n\nfunction loadChunkPath(chunkPath: ChunkPath, source?: SourceInfo): void {\n  if (!isJs(chunkPath)) {\n    // We only support loading JS chunks in Node.js.\n    // This branch can be hit when trying to load a CSS chunk.\n    return;\n  }\n\n  try {\n    const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n    const chunkModules: ModuleFactories = require(resolved);\n\n    for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {\n      if (!moduleFactories[moduleId]) {\n        moduleFactories[moduleId] = moduleFactory;\n      }\n    }\n  } catch (e) {\n    let errorMessage = `Failed to load chunk ${chunkPath}`;\n\n    if (source) {\n      errorMessage += ` from ${stringifySourceInfo(source)}`;\n    }\n\n    throw new Error(errorMessage, {\n      cause: e,\n    });\n  }\n}\n\nasync function loadChunkAsync(\n  source: SourceInfo,\n  chunkData: ChunkData\n): Promise<any> {\n  const chunkPath = typeof chunkData === \"string\" ? chunkData : chunkData.path;\n  if (!isJs(chunkPath)) {\n    // We only support loading JS chunks in Node.js.\n    // This branch can be hit when trying to load a CSS chunk.\n    return;\n  }\n\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  try {\n    const contents = await fs.readFile(resolved, \"utf-8\");\n\n    const localRequire = (id: string) => {\n      let resolvedId = require.resolve(id, {paths: [path.dirname(resolved)]});\n      return require(resolvedId);\n    }\n    const module = {\n      exports: {},\n    };\n    // TODO: Use vm.runInThisContext once our minimal supported Node.js version includes https://github.com/nodejs/node/pull/52153\n    // eslint-disable-next-line no-eval -- Can't use vm.runInThisContext due to https://github.com/nodejs/node/issues/52102\n    (0, eval)(\n      \"(function(module, exports, require, __dirname, __filename) {\" +\n        contents +\n        \"\\n})\" +\n        \"\\n//# sourceURL=\" + url.pathToFileURL(resolved),\n    )(module, module.exports, localRequire, path.dirname(resolved), resolved);\n\n    const chunkModules: ModuleFactories = module.exports;\n    for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {\n      if (!moduleFactories[moduleId]) {\n        moduleFactories[moduleId] = moduleFactory;\n      }\n    }\n  } catch (e) {\n    let errorMessage = `Failed to load chunk ${chunkPath}`;\n\n    if (source) {\n      errorMessage += ` from ${stringifySourceInfo(source)}`;\n    }\n\n    throw new Error(errorMessage, {\n      cause: e,\n    });\n  }\n}\n\nasync function loadChunkAsyncByUrl(source: SourceInfo, chunkUrl: string) {\n  const path = url.fileURLToPath(new URL(chunkUrl, RUNTIME_ROOT)) as ChunkPath;\n  return loadChunkAsync(source, path);\n}\n\nfunction loadWebAssembly(chunkPath: ChunkPath, imports: WebAssembly.Imports) {\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  return instantiateWebAssemblyFromPath(resolved, imports);\n}\n\nfunction loadWebAssemblyModule(chunkPath: ChunkPath) {\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  return compileWebAssemblyFromPath(resolved);\n}\n\nfunction getWorkerBlobURL(_chunks: ChunkPath[]): string {\n  throw new Error(\"Worker blobs are not implemented yet for Node.js\");\n}\n\nfunction instantiateModule(id: ModuleId, source: SourceInfo): ModuleWithDirection {\n  const moduleFactory = moduleFactories[id];\n  if (typeof moduleFactory !== \"function\") {\n    // This can happen if modules incorrectly handle HMR disposes/updates,\n    // e.g. when they keep a `setTimeout` around which still executes old code\n    // and contains e.g. a `require(\"something\")` call.\n    let instantiationReason;\n    switch (source.type) {\n      case SourceType.Runtime:\n        instantiationReason = `as a runtime entry of chunk ${source.chunkPath}`;\n        break;\n      case SourceType.Parent:\n        instantiationReason = `because it was required from module ${source.parentId}`;\n        break;\n      default:\n        invariant(source, (source) => `Unknown source type: ${source?.type}`);\n    }\n    throw new Error(\n      `Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`\n    );\n  }\n\n  let parents: ModuleId[];\n  switch (source.type) {\n    case SourceType.Runtime:\n      parents = [];\n      break;\n    case SourceType.Parent:\n      // No need to add this module as a child of the parent module here, this\n      // has already been taken care of in `getOrInstantiateModuleFromParent`.\n      parents = [source.parentId];\n      break;\n    default:\n      invariant(source, (source) => `Unknown source type: ${source?.type}`);\n  }\n\n  const module: ModuleWithDirection = {\n    exports: {},\n    error: undefined,\n    loaded: false,\n    id,\n    parents,\n    children: [],\n    namespaceObject: undefined,\n  };\n  moduleCache[id] = module;\n\n  // NOTE(alexkirsz) This can fail when the module encounters a runtime error.\n  try {\n    const r = commonJsRequire.bind(null, module);\n    moduleFactory.call(module.exports, {\n      a: asyncModule.bind(null, module),\n      e: module.exports,\n      r,\n      t: runtimeRequire,\n      x: externalRequire,\n      y: externalImport,\n      f: moduleContext,\n      i: esmImport.bind(null, module),\n      s: esmExport.bind(null, module, module.exports),\n      j: dynamicExport.bind(null, module, module.exports),\n      v: exportValue.bind(null, module),\n      n: exportNamespace.bind(null, module),\n      m: module,\n      c: moduleCache,\n      M: moduleFactories,\n      l: loadChunkAsync.bind(null, { type: SourceType.Parent, parentId: id }),\n      L: loadChunkAsyncByUrl.bind(null, { type: SourceType.Parent, parentId: id }),\n      w: loadWebAssembly,\n      u: loadWebAssemblyModule,\n      g: globalThis,\n      P: resolveAbsolutePath,\n      U: relativeURL,\n      R: createResolvePathFromModule(r),\n      b: getWorkerBlobURL,\n      z: requireStub,\n      __dirname: typeof module.id === \"string\" ? module.id.replace(/(^|\\/)\\/+$/, \"\") : module.id\n    });\n  } catch (error) {\n    module.error = error as any;\n    throw error;\n  }\n\n  module.loaded = true;\n  if (module.namespaceObject && module.exports !== module.namespaceObject) {\n    // in case of a circular dependency: cjs1 -> esm2 -> cjs1\n    interopEsm(module.exports, module.namespaceObject);\n  }\n\n  return module;\n}\n\n/**\n * Retrieves a module from the cache, or instantiate it if it is not cached.\n */\n// @ts-ignore\nfunction getOrInstantiateModuleFromParent(\n  id: ModuleId,\n  sourceModule: ModuleWithDirection\n): ModuleWithDirection {\n  const module = moduleCache[id];\n\n  if (sourceModule.children.indexOf(id) === -1) {\n    sourceModule.children.push(id);\n  }\n\n  if (module) {\n    if (module.parents.indexOf(sourceModule.id) === -1) {\n      module.parents.push(sourceModule.id);\n    }\n\n    return module;\n  }\n\n  return instantiateModule(id, {\n    type: SourceType.Parent,\n    parentId: sourceModule.id,\n  });\n}\n\n/**\n * Instantiates a runtime module.\n */\nfunction instantiateRuntimeModule(\n  moduleId: ModuleId,\n  chunkPath: ChunkPath\n): Module {\n  return instantiateModule(moduleId, { type: SourceType.Runtime, chunkPath });\n}\n\n/**\n * Retrieves a module from the cache, or instantiate it as a runtime module if it is not cached.\n */\n// @ts-ignore TypeScript doesn't separate this module space from the browser runtime\nfunction getOrInstantiateRuntimeModule(\n  moduleId: ModuleId,\n  chunkPath: ChunkPath\n): Module {\n  const module = moduleCache[moduleId];\n  if (module) {\n    if (module.error) {\n      throw module.error;\n    }\n    return module;\n  }\n\n  return instantiateRuntimeModule(moduleId, chunkPath);\n}\n\nconst regexJsUrl = /\\.js(?:\\?[^#]*)?(?:#.*)?$/;\n/**\n * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.\n */\nfunction isJs(chunkUrlOrPath: ChunkUrl | ChunkPath): boolean {\n  return regexJsUrl.test(chunkUrlOrPath);\n}\n\nmodule.exports = {\n  getOrInstantiateRuntimeModule,\n  loadChunk,\n};\n"],"names":[],"mappings":"AAAA,oDAAoD,GAEpD,mDAAmD;AACnD,+DAA+D;AAC/D,+DAA+D;AAC/D,0DAA0D;AAE1D,IAAA,AAAK,oCAAA;IACH;;;GAGC;IAED;;GAEC;WARE;EAAA;AAsBL,QAAQ,GAAG,CAAC,SAAS,GAAG;AAExB,SAAS,oBAAoB,MAAkB;IAC7C,OAAQ,OAAO,IAAI;QACjB;YACE,OAAO,CAAC,kBAAkB,EAAE,OAAO,SAAS,EAAE;QAChD;YACE,OAAO,CAAC,cAAc,EAAE,OAAO,QAAQ,EAAE;QAC3C;YACE,UAAU,QAAQ,CAAC,SAAW,CAAC,qBAAqB,EAAE,QAAQ,MAAM;IACxE;AACF;AAoBA,MAAM,MAAM,QAAQ;AACpB,MAAM,KAAK,QAAQ;AAEnB,MAAM,kBAAmC,OAAO,MAAM,CAAC;AACvD,MAAM,cAAgD,OAAO,MAAM,CAAC;AAEpE;;CAEC,GACD,SAAS,4BACP,QAAuC;IAEvC,OAAO,S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AAI,SAAQ;QACV,IAAI,QAAO,KAAK,EAAE;YAChB,MAAM,QAAO,KAAK;QACpB;QACA,OAAO;IACT;IAEA,OAAO,yBAAyB,UAAU;AAC5C;AAEA,MAAM,aAAa;AACnB;;CAEC,GACD,SAAS,KAAK,cAAoC;IAChD,OAAO,WAAW,IAAI,CAAC;AACzB;AAEA,OAAO,OAAO,GAAG;IACf;IACA;AACF","ignoreList":[0]}}]
+    {"offset": {"line": 417, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/nodejs/runtime.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/// <reference path=\"../shared/runtime-utils.ts\" />\n/// <reference path=\"../shared-node/base-externals-utils.ts\" />\n/// <reference path=\"../shared-node/node-externals-utils.ts\" />\n/// <reference path=\"../shared-node/node-wasm-utils.ts\" />\n\nenum SourceType {\n  /**\n   * The module was instantiated because it was included in an evaluated chunk's\n   * runtime.\n   */\n  Runtime = 0,\n  /**\n   * The module was instantiated because a parent module imported it.\n   */\n  Parent = 1,\n}\n\ntype SourceInfo =\n  | {\n      type: SourceType.Runtime;\n      chunkPath: ChunkPath;\n    }\n  | {\n      type: SourceType.Parent;\n      parentId: ModuleId;\n    };\n\nprocess.env.TURBOPACK = '1';\n\nfunction stringifySourceInfo(source: SourceInfo): string {\n  switch (source.type) {\n    case SourceType.Runtime:\n      return `runtime for chunk ${source.chunkPath}`;\n    case SourceType.Parent:\n      return `parent module ${source.parentId}`;\n    default:\n      invariant(source, (source) => `Unknown source type: ${source?.type}`);\n  }\n}\n\ntype ExternalRequire = (\n  id: ModuleId,\n  thunk: () => any,\n  esm?: boolean\n) => Exports | EsmNamespaceObject;\ntype ExternalImport = (id: ModuleId) => Promise<Exports | EsmNamespaceObject>;\n\ninterface TurbopackNodeBuildContext extends TurbopackBaseContext<Module> {\n  R: ResolvePathFromModule;\n  x: ExternalRequire;\n  y: ExternalImport;\n}\n\ntype ModuleFactory = (\n  this: Module[\"exports\"],\n  context: TurbopackNodeBuildContext\n) => undefined;\n\nconst url = require(\"url\") as typeof import('url');\nconst fs = require(\"fs/promises\") as typeof import('fs/promises');\n\nconst moduleFactories: ModuleFactories = Object.create(null);\nconst moduleCache: ModuleCache<ModuleWithDirection> = Object.create(null);\n\n/**\n * Returns an absolute path to the given module's id.\n */\nfunction createResolvePathFromModule(\n  resolver: (moduleId: string) => Exports\n): (moduleId: string) => string {\n  return function resolvePathFromModule(moduleId: string): string {\n    const exported = resolver(moduleId);\n    const exportedPath = exported?.default ?? exported;\n    if (typeof exportedPath !== \"string\") {\n      return exported as any;\n    }\n\n    const strippedAssetPrefix = exportedPath.slice(ASSET_PREFIX.length);\n    const resolved = path.resolve(\n      RUNTIME_ROOT,\n      strippedAssetPrefix\n    );\n\n    return url.pathToFileURL(resolved).href;\n  };\n}\n\nfunction loadChunk(chunkData: ChunkData, source?: SourceInfo): void {\n  if (typeof chunkData === \"string\") {\n    return loadChunkPath(chunkData, source);\n  } else {\n    return loadChunkPath(chunkData.path, source);\n  }\n}\n\nconst loadedChunks = new Set<ChunkPath>();\n\nfunction loadChunkPath(chunkPath: ChunkPath, source?: SourceInfo): void {\n  if (!isJs(chunkPath)) {\n    // We only support loading JS chunks in Node.js.\n    // This branch can be hit when trying to load a CSS chunk.\n    return;\n  }\n\n  if (loadedChunks.has(chunkPath)) {\n    return;\n  }\n\n  try {\n    const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n    const chunkModules: ModuleFactories = require(resolved);\n\n    for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {\n      if (!moduleFactories[moduleId]) {\n        moduleFactories[moduleId] = moduleFactory;\n      }\n    }\n    loadedChunks.add(chunkPath);\n  } catch (e) {\n    let errorMessage = `Failed to load chunk ${chunkPath}`;\n\n    if (source) {\n      errorMessage += ` from ${stringifySourceInfo(source)}`;\n    }\n\n    throw new Error(errorMessage, {\n      cause: e,\n    });\n  }\n}\n\nasync function loadChunkAsync(\n  source: SourceInfo,\n  chunkData: ChunkData\n): Promise<any> {\n  const chunkPath = typeof chunkData === \"string\" ? chunkData : chunkData.path;\n  if (!isJs(chunkPath)) {\n    // We only support loading JS chunks in Node.js.\n    // This branch can be hit when trying to load a CSS chunk.\n    return;\n  }\n\n  if (loadedChunks.has(chunkPath)) {\n    return;\n  }\n\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  try {\n    const contents = await fs.readFile(resolved, \"utf-8\");\n\n    const localRequire = (id: string) => {\n      let resolvedId = require.resolve(id, {paths: [path.dirname(resolved)]});\n      return require(resolvedId);\n    }\n    const module = {\n      exports: {},\n    };\n    // TODO: Use vm.runInThisContext once our minimal supported Node.js version includes https://github.com/nodejs/node/pull/52153\n    // eslint-disable-next-line no-eval -- Can't use vm.runInThisContext due to https://github.com/nodejs/node/issues/52102\n    (0, eval)(\n      \"(function(module, exports, require, __dirname, __filename) {\" +\n        contents +\n        \"\\n})\" +\n        \"\\n//# sourceURL=\" + url.pathToFileURL(resolved),\n    )(module, module.exports, localRequire, path.dirname(resolved), resolved);\n\n    const chunkModules: ModuleFactories = module.exports;\n    for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {\n      if (!moduleFactories[moduleId]) {\n        moduleFactories[moduleId] = moduleFactory;\n      }\n    }\n    loadedChunks.add(chunkPath);\n  } catch (e) {\n    let errorMessage = `Failed to load chunk ${chunkPath}`;\n\n    if (source) {\n      errorMessage += ` from ${stringifySourceInfo(source)}`;\n    }\n\n    throw new Error(errorMessage, {\n      cause: e,\n    });\n  }\n}\n\nasync function loadChunkAsyncByUrl(source: SourceInfo, chunkUrl: string) {\n  const path = url.fileURLToPath(new URL(chunkUrl, RUNTIME_ROOT)) as ChunkPath;\n  return loadChunkAsync(source, path);\n}\n\nfunction loadWebAssembly(chunkPath: ChunkPath, imports: WebAssembly.Imports) {\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  return instantiateWebAssemblyFromPath(resolved, imports);\n}\n\nfunction loadWebAssemblyModule(chunkPath: ChunkPath) {\n  const resolved = path.resolve(RUNTIME_ROOT, chunkPath);\n\n  return compileWebAssemblyFromPath(resolved);\n}\n\nfunction getWorkerBlobURL(_chunks: ChunkPath[]): string {\n  throw new Error(\"Worker blobs are not implemented yet for Node.js\");\n}\n\nfunction instantiateModule(id: ModuleId, source: SourceInfo): ModuleWithDirection {\n  const moduleFactory = moduleFactories[id];\n  if (typeof moduleFactory !== \"function\") {\n    // This can happen if modules incorrectly handle HMR disposes/updates,\n    // e.g. when they keep a `setTimeout` around which still executes old code\n    // and contains e.g. a `require(\"something\")` call.\n    let instantiationReason;\n    switch (source.type) {\n      case SourceType.Runtime:\n        instantiationReason = `as a runtime entry of chunk ${source.chunkPath}`;\n        break;\n      case SourceType.Parent:\n        instantiationReason = `because it was required from module ${source.parentId}`;\n        break;\n      default:\n        invariant(source, (source) => `Unknown source type: ${source?.type}`);\n    }\n    throw new Error(\n      `Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`\n    );\n  }\n\n  let parents: ModuleId[];\n  switch (source.type) {\n    case SourceType.Runtime:\n      parents = [];\n      break;\n    case SourceType.Parent:\n      // No need to add this module as a child of the parent module here, this\n      // has already been taken care of in `getOrInstantiateModuleFromParent`.\n      parents = [source.parentId];\n      break;\n    default:\n      invariant(source, (source) => `Unknown source type: ${source?.type}`);\n  }\n\n  const module: ModuleWithDirection = {\n    exports: {},\n    error: undefined,\n    loaded: false,\n    id,\n    parents,\n    children: [],\n    namespaceObject: undefined,\n  };\n  moduleCache[id] = module;\n\n  // NOTE(alexkirsz) This can fail when the module encounters a runtime error.\n  try {\n    const r = commonJsRequire.bind(null, module);\n    moduleFactory.call(module.exports, {\n      a: asyncModule.bind(null, module),\n      e: module.exports,\n      r,\n      t: runtimeRequire,\n      x: externalRequire,\n      y: externalImport,\n      f: moduleContext,\n      i: esmImport.bind(null, module),\n      s: esmExport.bind(null, module, module.exports),\n      j: dynamicExport.bind(null, module, module.exports),\n      v: exportValue.bind(null, module),\n      n: exportNamespace.bind(null, module),\n      m: module,\n      c: moduleCache,\n      M: moduleFactories,\n      l: loadChunkAsync.bind(null, { type: SourceType.Parent, parentId: id }),\n      L: loadChunkAsyncByUrl.bind(null, { type: SourceType.Parent, parentId: id }),\n      w: loadWebAssembly,\n      u: loadWebAssemblyModule,\n      g: globalThis,\n      P: resolveAbsolutePath,\n      U: relativeURL,\n      R: createResolvePathFromModule(r),\n      b: getWorkerBlobURL,\n      z: requireStub,\n      __dirname: typeof module.id === \"string\" ? module.id.replace(/(^|\\/)\\/+$/, \"\") : module.id\n    });\n  } catch (error) {\n    module.error = error as any;\n    throw error;\n  }\n\n  module.loaded = true;\n  if (module.namespaceObject && module.exports !== module.namespaceObject) {\n    // in case of a circular dependency: cjs1 -> esm2 -> cjs1\n    interopEsm(module.exports, module.namespaceObject);\n  }\n\n  return module;\n}\n\n/**\n * Retrieves a module from the cache, or instantiate it if it is not cached.\n */\n// @ts-ignore\nfunction getOrInstantiateModuleFromParent(\n  id: ModuleId,\n  sourceModule: ModuleWithDirection\n): ModuleWithDirection {\n  const module = moduleCache[id];\n\n  if (sourceModule.children.indexOf(id) === -1) {\n    sourceModule.children.push(id);\n  }\n\n  if (module) {\n    if (module.parents.indexOf(sourceModule.id) === -1) {\n      module.parents.push(sourceModule.id);\n    }\n\n    return module;\n  }\n\n  return instantiateModule(id, {\n    type: SourceType.Parent,\n    parentId: sourceModule.id,\n  });\n}\n\n/**\n * Instantiates a runtime module.\n */\nfunction instantiateRuntimeModule(\n  moduleId: ModuleId,\n  chunkPath: ChunkPath\n): Module {\n  return instantiateModule(moduleId, { type: SourceType.Runtime, chunkPath });\n}\n\n/**\n * Retrieves a module from the cache, or instantiate it as a runtime module if it is not cached.\n */\n// @ts-ignore TypeScript doesn't separate this module space from the browser runtime\nfunction getOrInstantiateRuntimeModule(\n  moduleId: ModuleId,\n  chunkPath: ChunkPath\n): Module {\n  const module = moduleCache[moduleId];\n  if (module) {\n    if (module.error) {\n      throw module.error;\n    }\n    return module;\n  }\n\n  return instantiateRuntimeModule(moduleId, chunkPath);\n}\n\nconst regexJsUrl = /\\.js(?:\\?[^#]*)?(?:#.*)?$/;\n/**\n * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.\n */\nfunction isJs(chunkUrlOrPath: ChunkUrl | ChunkPath): boolean {\n  return regexJsUrl.test(chunkUrlOrPath);\n}\n\nmodule.exports = {\n  getOrInstantiateRuntimeModule,\n  loadChunk,\n};\n"],"names":[],"mappings":"AAAA,oDAAoD,GAEpD,mDAAmD;AACnD,+DAA+D;AAC/D,+DAA+D;AAC/D,0DAA0D;AAE1D,IAAA,AAAK,oCAAA;IACH;;;GAGC;IAED;;GAEC;WARE;EAAA;AAsBL,QAAQ,GAAG,CAAC,SAAS,GAAG;AAExB,SAAS,oBAAoB,MAAkB;IAC7C,OAAQ,OAAO,IAAI;QACjB;YACE,OAAO,CAAC,kBAAkB,EAAE,OAAO,SAAS,EAAE;QAChD;YACE,OAAO,CAAC,cAAc,EAAE,OAAO,QAAQ,EAAE;QAC3C;YACE,UAAU,QAAQ,CAAC,SAAW,CAAC,qBAAqB,EAAE,QAAQ,MAAM;IACxE;AACF;AAoBA,MAAM,MAAM,QAAQ;AACpB,MAAM,KAAK,QAAQ;AAEnB,MAAM,kBAAmC,OAAO,MAAM,CAAC;AACvD,MAAM,cAAgD,OAAO,MAAM,CAAC;AAEpE;;CAEC,GACD,SAAS,4BACP,QAAuC;IAEvC,OAAO,SAAS,sBAAsB,QAAgB;QACpD,MAAM,WAAW,SAAS;QAC1B,MAAM,eAAe,UAAU,WAAW;QAC1C,IAAI,OAAO,iBAAiB,UAAU;YACpC,OAAO;QACT;QAEA,MAAM,sBAAsB,aAAa,KAAK,CAAC,aAAa,MAAM;QAClE,MAAM,WAAW,KAAK,OAAO,CAC3B,cACA;QAGF,OAAO,IAAI,aAAa,CAAC,UAAU,IAAI;IACzC;AACF;AAEA,SAAS,UAAU,SAAoB,EAAE,MAAmB;IAC1D,IA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,GACD,SAAS,KAAK,cAAoC;IAChD,OAAO,WAAW,IAAI,CAAC;AACzB;AAEA,OAAO,OAAO,GAAG;IACf;IACA;AACF","ignoreList":[0]}}]
 }
\ No newline at end of file

filename: turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_dev_runtime/output/b1abf_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_75df6705.js
patch: @@ -1486,6 +1486,7 @@ async function loadWebAssemblyModule(_source, wasmChunkPath) {
             });
             resolver = {
                 resolved: false,
+                loadingStarted: false,
                 promise,
                 resolve: ()=>{
                     resolver.resolved = true;
@@ -1502,12 +1503,13 @@ async function loadWebAssemblyModule(_source, wasmChunkPath) {
     * has been loaded.
     */ function doLoadChunk(chunkUrl, source) {
         const resolver = getOrCreateResolver(chunkUrl);
-        if (resolver.resolved) {
+        if (resolver.loadingStarted) {
             return resolver.promise;
         }
         if (source.type === SourceType.Runtime) {
             // We don't need to load chunks references from runtime code, as they're already
             // present in the DOM.
+            resolver.loadingStarted = true;
             if (isCss(chunkUrl)) {
                 // CSS chunks do not register themselves, and as such must be marked as
                 // loaded instantly.
@@ -1576,6 +1578,7 @@ async function loadWebAssemblyModule(_source, wasmChunkPath) {
                 throw new Error(`can't infer type of chunk from URL ${chunkUrl}`);
             }
         }
+        resolver.loadingStarted = true;
         return resolver.promise;
     }
 })();