Unverified Commit b3f77636 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix chunk loading when using `__turbopack_load_by_url__` with query (#88899)

- if you `await __turbopack_load_by_url__ `, it waits for the exact chunk url you passed in to load
- but when that chunk actually loads, it registers itself with `stripQuery(chunkurl)+CHUNK_SUFFIX`

so there was mismatch if you load a chunk from a different deployment and thus `await __turbopack_load_by_url__` never resolves



----

Very confused about what's going on here:

```
 FAIL   Turbopack  test/e2e/app-dir/segment-cache/deployment-skew/deployment-skew.test.ts (61.629 s)
  segment cache (deployment skew)
    with BUILD_ID
      ✓ does not crash when prefetching a dynamic, non-PPR page on a different deployment (11673 ms)
      ✓ does not crash when prefetching a static page on a different deployment (10744 ms)
    with NEXT_DEPLOYMENT_ID
      ✓ does not crash when prefetching a dynamic, non-PPR page on a different deployment (10924 ms)
      ✕ does not crash when prefetching a static page on a different deployment (15756 ms)

  ● segment cache (deployment skew) › with NEXT_DEPLOYMENT_ID › does not crash when prefetching a static page on a different deployment

    page.waitForSelector: Timeout 5000ms exceeded.
    Call log:
      - waiting for locator('#build-id') to be visible

      519 |
      520 |     return this.startChain(async () => {
    > 521 |       const el = await page.waitForSelector(selector, {
          |                             ^
      522 |         timeout,
      523 |         state,
      524 |       })

      at waitForSelector (lib/browsers/playwright.ts:521:29)
      at Playwright._chain (lib/browsers/playwright.ts:651:23)
      at Playwright._chain [as startChain] (lib/browsers/playwright.ts:632:17)
      at Playwright.startChain [as waitForElementByCss] (lib/browsers/playwright.ts:520:17)
      at Playwright.waitForElementByCss [as elementByCss] (lib/browsers/playwright.ts:405:17)
      at Playwright.elementByCss [as elementById] (lib/browsers/playwright.ts:425:17)
      at Object.elementById (e2e/app-dir/segment-cache/deployment-skew/deployment-skew.test.ts:122:37)

```

In the browser debugger, this line here in `fetchServerResponse` never returns, so there is actually no navigation at all (neither SPA nor MPA) when clicking the link, should be doing an MPA nav

https://github.com/vercel/next.js/blob/d4e64f52bb9aeb5dbcf6bb484f204742b2e3d743/packages/next/src/client/components/router-reducer/fetch-server-response.ts#L242
parent cb1dbfb8
...@@ -2,5 +2,10 @@ import { connection } from 'next/server' ...@@ -2,5 +2,10 @@ import { connection } from 'next/server'
export default async function TargetPage() { export default async function TargetPage() {
await connection() await connection()
return <div id="build-id">Build ID: {process.env.NEXT_PUBLIC_BUILD_ID}</div> return (
<div id="build-id">
Build ID:{' '}
{process.env.NEXT_PUBLIC_BUILD_ID ?? process.env.NEXT_DEPLOYMENT_ID}
</div>
)
} }
export default function TargetPage() { export default function TargetPage() {
return <div id="build-id">Build ID: {process.env.NEXT_PUBLIC_BUILD_ID}</div> return (
<div id="build-id">
Build ID:{' '}
{process.env.NEXT_PUBLIC_BUILD_ID ?? process.env.NEXT_DEPLOYMENT_ID}
</div>
)
} }
import { build } from './servers.mjs' import { build } from './servers.mjs'
build() build('DEPLOYMENT_ID')
// build('BUILD_ID')
...@@ -24,18 +24,40 @@ describe('segment cache (deployment skew)', () => { ...@@ -24,18 +24,40 @@ describe('segment cache (deployment skew)', () => {
let cleanup: () => Promise<void> let cleanup: () => Promise<void>
let port: number let port: number
beforeAll(async () => { describe('with BUILD_ID', () => {
build() beforeAll(async () => {
const proxyPort = (port = await findPort()) build('BUILD_ID')
const nextPort1 = await findPort() const proxyPort = (port = await findPort())
const nextPort2 = await findPort() const nextPort1 = await findPort()
cleanup = await start(proxyPort, nextPort1, nextPort2) const nextPort2 = await findPort()
cleanup = await start(proxyPort, nextPort1, nextPort2, 'BUILD_ID')
})
afterAll(async () => {
await cleanup()
})
runTests(() => port)
}) })
afterAll(async () => { describe('with NEXT_DEPLOYMENT_ID', () => {
await cleanup() beforeAll(async () => {
build('DEPLOYMENT_ID')
const proxyPort = (port = await findPort())
const nextPort1 = await findPort()
const nextPort2 = await findPort()
cleanup = await start(proxyPort, nextPort1, nextPort2, 'DEPLOYMENT_ID')
})
afterAll(async () => {
await cleanup()
})
runTests(() => port)
}) })
})
function runTests(getPort: () => number) {
it( it(
'does not crash when prefetching a dynamic, non-PPR page ' + 'does not crash when prefetching a dynamic, non-PPR page ' +
'on a different deployment', 'on a different deployment',
...@@ -44,7 +66,7 @@ describe('segment cache (deployment skew)', () => { ...@@ -44,7 +66,7 @@ describe('segment cache (deployment skew)', () => {
// from a different deployment, when PPR is disabled. Once PPR is the // from a different deployment, when PPR is disabled. Once PPR is the
// default, it's OK to rewrite this to use the latest APIs. // default, it's OK to rewrite this to use the latest APIs.
let act let act
const browser = await webdriver(port, '/', { const browser = await webdriver(getPort(), '/', {
beforePageLoad(p: Playwright.Page) { beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p) act = createRouterAct(p)
}, },
...@@ -76,7 +98,7 @@ describe('segment cache (deployment skew)', () => { ...@@ -76,7 +98,7 @@ describe('segment cache (deployment skew)', () => {
async () => { async () => {
// Same as the previous test, but for a static page // Same as the previous test, but for a static page
let act let act
const browser = await webdriver(port, '/', { const browser = await webdriver(getPort(), '/', {
beforePageLoad(p: Playwright.Page) { beforePageLoad(p: Playwright.Page) {
act = createRouterAct(p) act = createRouterAct(p)
}, },
...@@ -102,4 +124,4 @@ describe('segment cache (deployment skew)', () => { ...@@ -102,4 +124,4 @@ describe('segment cache (deployment skew)', () => {
}, },
60 * 1000 60 * 1000
) )
}) }
const BUILD_ID = process.env.BUILD_ID const BUILD_ID = process.env.BUILD_ID
if (!BUILD_ID) { if (!BUILD_ID && !process.env.NEXT_DEPLOYMENT_ID) {
throw new Error('BUILD_ID is not set') throw new Error('Neither BUILD_ID nor NEXT_DEPLOYMENT_ID is set')
} }
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
const nextConfig = { const nextConfig = {
distDir: '.next.' + BUILD_ID, distDir: '.next.' + (BUILD_ID ?? process.env.NEXT_DEPLOYMENT_ID),
async generateBuildId() { generateBuildId:
return BUILD_ID BUILD_ID &&
}, (async () => {
return BUILD_ID
}),
} }
module.exports = nextConfig module.exports = nextConfig
...@@ -7,13 +7,26 @@ import process from 'node:process' ...@@ -7,13 +7,26 @@ import process from 'node:process'
const dir = dirname(fileURLToPath(import.meta.url)) const dir = dirname(fileURLToPath(import.meta.url))
async function spawnNext(buildId, port) { function getEnv(id, mode) {
const child = spawn('pnpm', ['next', 'start', '-p', port, dir], { if (mode === 'BUILD_ID') {
env: { return {
...process.env,
BUILD_ID: id,
NEXT_PUBLIC_BUILD_ID: id,
}
} else if (mode === 'DEPLOYMENT_ID') {
return {
...process.env, ...process.env,
BUILD_ID: buildId, NEXT_DEPLOYMENT_ID: id,
NEXT_PUBLIC_BUILD_ID: buildId, }
}, } else {
throw new Error('invalid mode ' + mode)
}
}
async function spawnNext(id, mode, port) {
const child = spawn('pnpm', ['next', 'start', '-p', port, dir], {
env: getEnv(id, mode),
stdio: ['inherit', 'pipe', 'inherit'], stdio: ['inherit', 'pipe', 'inherit'],
}) })
...@@ -36,32 +49,29 @@ async function spawnNext(buildId, port) { ...@@ -36,32 +49,29 @@ async function spawnNext(buildId, port) {
}) })
} }
export function buildNext(buildId) { export function buildNext(id, mode) {
spawnSync('pnpm', ['next', 'build', dir], { spawnSync('pnpm', ['next', 'build', dir], {
env: { env: getEnv(id, mode),
...process.env,
BUILD_ID: buildId,
NEXT_PUBLIC_BUILD_ID: buildId,
},
stdio: 'inherit', stdio: 'inherit',
}) })
} }
export function build() { export function build(mode) {
buildNext('1') buildNext('1', mode)
buildNext('2') buildNext('2', mode)
} }
export async function start( export async function start(
mainPort = 3000, mainPort = 3000,
nextPort1 = mainPort + 1, nextPort1 = mainPort + 1,
nextPort2 = mainPort + 2 nextPort2 = mainPort + 2,
mode = 'BUILD_ID'
) { ) {
// Start two different Next.js servers, one with BUILD_ID=1 and one // Start two different Next.js servers, one with BUILD_ID=1 and one
// with BUILD_ID=2 // with BUILD_ID=2
const [next1, next2] = await Promise.all([ const [next1, next2] = await Promise.all([
spawnNext('1', nextPort1), spawnNext('1', mode, nextPort1),
spawnNext('2', nextPort2), spawnNext('2', mode, nextPort2),
]) ])
// Create a proxy server. If search params include `deployment=2`, proxy to // Create a proxy server. If search params include `deployment=2`, proxy to
......
import { start } from './servers.mjs' import { start } from './servers.mjs'
await start() // await start(undefined, undefined, undefined, 'BUILD_ID')
await start(undefined, undefined, undefined, 'DEPLOYMENT_ID')
module.exports = {
experimental: {
turbopackMinify: false,
turbopackModuleIds: 'named',
turbopackScopeHoisting: false,
},
}
...@@ -85,7 +85,9 @@ function instantiateModule( ...@@ -85,7 +85,9 @@ function instantiateModule(
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
function registerChunk(registration: ChunkRegistration) { function registerChunk(registration: ChunkRegistration) {
const chunkPath = getPathFromScript(registration[0]) const chunk = getChunkFromRegistration(registration[0]) as
| ChunkScript
| ChunkPath
let runtimeParams: RuntimeParams | undefined let runtimeParams: RuntimeParams | undefined
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
...@@ -99,5 +101,5 @@ function registerChunk(registration: ChunkRegistration) { ...@@ -99,5 +101,5 @@ function registerChunk(registration: ChunkRegistration) {
) )
} }
return BACKEND.registerChunk(chunkPath, runtimeParams) return BACKEND.registerChunk(chunk, runtimeParams)
} }
...@@ -1132,12 +1132,15 @@ function markChunkListAsRuntime(chunkListPath: ChunkListPath) { ...@@ -1132,12 +1132,15 @@ function markChunkListAsRuntime(chunkListPath: ChunkListPath) {
} }
function registerChunk(registration: ChunkRegistration) { function registerChunk(registration: ChunkRegistration) {
const chunkPath = getPathFromScript(registration[0]) const chunk = getChunkFromRegistration(registration[0]) as
| ChunkPath
| ChunkScript
let runtimeParams: RuntimeParams | undefined let runtimeParams: RuntimeParams | undefined
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1] as RuntimeParams runtimeParams = registration[1] as RuntimeParams
} else { } else {
let chunkPath = getPathFromScript(chunk)
runtimeParams = undefined runtimeParams = undefined
installCompressedModuleFactories( installCompressedModuleFactories(
registration as CompressedModuleFactories, registration as CompressedModuleFactories,
...@@ -1146,14 +1149,16 @@ function registerChunk(registration: ChunkRegistration) { ...@@ -1146,14 +1149,16 @@ function registerChunk(registration: ChunkRegistration) {
(id: ModuleId) => addModuleToChunk(id, chunkPath) (id: ModuleId) => addModuleToChunk(id, chunkPath)
) )
} }
return BACKEND.registerChunk(chunkPath, runtimeParams) return BACKEND.registerChunk(chunk, runtimeParams)
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ */
function registerChunkList(chunkList: ChunkList) { function registerChunkList(chunkList: ChunkList) {
const chunkListScript = chunkList.script const chunkListScript = getChunkFromRegistration(chunkList.script) as
| ChunkListPath
| ChunkListScript
const chunkListPath = getPathFromScript(chunkListScript) const chunkListPath = getPathFromScript(chunkListScript)
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath as string as ChunkPath) BACKEND.registerChunk(chunkListPath as string as ChunkPath)
......
...@@ -41,13 +41,18 @@ type RuntimeParams = { ...@@ -41,13 +41,18 @@ type RuntimeParams = {
runtimeModuleIds: ModuleId[] runtimeModuleIds: ModuleId[]
} }
type ChunkRegistrationChunk =
| ChunkPath
| { getAttribute: (name: string) => string | null }
| undefined
type ChunkRegistration = [ type ChunkRegistration = [
chunkPath: ChunkScript, chunkPath: ChunkRegistrationChunk,
...([RuntimeParams] | CompressedModuleFactories), ...([RuntimeParams] | CompressedModuleFactories),
] ]
type ChunkList = { type ChunkList = {
script: ChunkListScript script: ChunkRegistrationChunk
chunks: ChunkData[] chunks: ChunkData[]
source: 'entry' | 'dynamic' source: 'entry' | 'dynamic'
} }
...@@ -74,7 +79,10 @@ enum SourceType { ...@@ -74,7 +79,10 @@ enum SourceType {
type SourceData = ChunkPath | ModuleId | ModuleId[] | undefined type SourceData = ChunkPath | ModuleId | ModuleId[] | undefined
interface RuntimeBackend { interface RuntimeBackend {
registerChunk: (chunkPath: ChunkPath, params?: RuntimeParams) => void registerChunk: (
chunkPath: ChunkPath | ChunkScript,
params?: RuntimeParams
) => void
/** /**
* Returns the same Promise for the same chunk URL. * Returns the same Promise for the same chunk URL.
*/ */
...@@ -389,10 +397,7 @@ function getPathFromScript( ...@@ -389,10 +397,7 @@ function getPathFromScript(
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript as ChunkPath | ChunkListPath return chunkScript as ChunkPath | ChunkListPath
} }
const chunkUrl = const chunkUrl = chunkScript.src!
typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined'
? TURBOPACK_NEXT_CHUNK_URLS.pop()!
: chunkScript.getAttribute('src')!
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')) const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
const path = src.startsWith(CHUNK_BASE_PATH) const path = src.startsWith(CHUNK_BASE_PATH)
? src.slice(CHUNK_BASE_PATH.length) ? src.slice(CHUNK_BASE_PATH.length)
...@@ -400,6 +405,37 @@ function getPathFromScript( ...@@ -400,6 +405,37 @@ function getPathFromScript(
return path as ChunkPath | ChunkListPath return path as ChunkPath | ChunkListPath
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/
function getUrlFromScript(chunk: ChunkPath | ChunkScript): ChunkUrl {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk)
} else {
// This is already exactly what we want
return chunk.src! as ChunkUrl
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/
function getChunkFromRegistration(
chunk: ChunkRegistrationChunk
): ChunkPath | CurrentScript {
if (typeof chunk === 'string') {
return chunk
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return { src: TURBOPACK_NEXT_CHUNK_URLS.pop()! } as CurrentScript
} else {
throw new Error('chunk path empty but not in a worker')
}
} else {
return { src: chunk.getAttribute('src')! } as CurrentScript
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/ const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
......
...@@ -37,8 +37,9 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map() ...@@ -37,8 +37,9 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map()
;(() => { ;(() => {
BACKEND = { BACKEND = {
async registerChunk(chunkPath, params) { async registerChunk(chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath) let chunkPath = getPathFromScript(chunk)
let chunkUrl = getUrlFromScript(chunk)
const resolver = getOrCreateResolver(chunkUrl) const resolver = getOrCreateResolver(chunkUrl)
resolver.resolve() resolver.resolve()
......
...@@ -24,7 +24,9 @@ let BACKEND: RuntimeBackend ...@@ -24,7 +24,9 @@ let BACKEND: RuntimeBackend
// registered before any of them are instantiated. // registered before any of them are instantiated.
// Furthermore, modules must be instantiated synchronously, hence we don't // Furthermore, modules must be instantiated synchronously, hence we don't
// use promises here. // use promises here.
registerChunk(chunkPath, params) { registerChunk(chunk, params) {
let chunkPath = getPathFromScript(chunk)
registeredChunks.add(chunkPath) registeredChunks.add(chunkPath)
instantiateDependentChunks(chunkPath) instantiateDependentChunks(chunkPath)
......
/** /*
* This file contains runtime types that are shared between all TurboPack * This file contains runtime types that are shared between all TurboPack
* ECMAScript runtimes. * ECMAScript runtimes.
* *
...@@ -7,15 +7,23 @@ ...@@ -7,15 +7,23 @@
* specific to the runtime context. * specific to the runtime context.
*/ */
type CurrentScript = { getAttribute: (name: string) => string | null } type CurrentScript = { src: ChunkUrl | null }
type ChunkListPath = string & { readonly brand: unique symbol } type ChunkListPath = string & { readonly brand: unique symbol }
type ChunkListScript = CurrentScript & { readonly brand: unique symbol } type ChunkListScript = CurrentScript & { readonly brand: unique symbol }
/**
* The path of a chunk (an internal identifier used by Turbopack for tracking chunk loading), i.e.
* excluding CHUNK_BASE_PATH and CHUNK_SUFFIX, e.g. `static/chunks/21a106126841c540.js`
*/
type ChunkPath = string & { readonly brand: unique symbol } type ChunkPath = string & { readonly brand: unique symbol }
type ChunkScript = CurrentScript & { readonly brand: unique symbol } type ChunkScript = CurrentScript & { readonly brand: unique symbol }
/**
* The URL of a chunk (what will be requested from the server), i.e. including CHUNK_BASE_PATH and
* CHUNK_SUFFIX), e.g. `/_next/static/chunks/21a106126841c540.js?dpl=1123123`
*/
type ChunkUrl = string & { readonly brand: unique symbol } type ChunkUrl = string & { readonly brand: unique symbol }
// The dependency specifier when importing externals /** The dependency specifier when importing externals */
type DependencySpecifier = string type DependencySpecifier = string
// This is a string in development and a number in production (both arbitrary, implementation defined) /** This is a string in development and a number in production (both arbitrary, implementation defined) */
type ModuleId = string | number type ModuleId = string | number
interface Exports { interface Exports {
...@@ -68,9 +76,11 @@ type LoadWebAssemblyModule = ( ...@@ -68,9 +76,11 @@ type LoadWebAssemblyModule = (
type ModuleCache<M> = Record<ModuleId, M> type ModuleCache<M> = Record<ModuleId, M>
// TODO properly type values here // TODO properly type values here
type ModuleFactories = Map<ModuleId, Function> type ModuleFactories = Map<ModuleId, Function>
// This is an alternating, non-empty module factory functions and module ids /**
// [id1, id2..., factory1, id3, factory2, id4, id5, factory3] * This is an alternating, non-empty arrow of module factory functions and module ids
// There are multiple ids to support scope hoisting modules * `[id1, id2..., factory1, id3, factory2, id4, id5, factory3]`
* There can be multiple ids to support scope hoisted merged modules
*/
type CompressedModuleFactories = Array<ModuleId | Function> type CompressedModuleFactories = Array<ModuleId | Function>
type RelativeURL = (inputUrl: string) => void type RelativeURL = (inputUrl: string) => void
......
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="aaeb9570-a56b-3d14-e7e3-4dfbc2550f68")}catch(e){}}(); ;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="03178dfb-da5f-714f-0925-63c49edb4e28")}catch(e){}}();
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([ (globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js", "output/ba425_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0b8736b3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0b8736b3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -727,11 +727,40 @@ function getPathFromScript(chunkScript) { ...@@ -727,11 +727,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1565,21 +1594,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1565,21 +1594,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1622,8 +1652,9 @@ let BACKEND; ...@@ -1622,8 +1652,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
...@@ -1873,5 +1904,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -1873,5 +1904,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=aaeb9570-a56b-3d14-e7e3-4dfbc2550f68 //# debugId=03178dfb-da5f-714f-0925-63c49edb4e28
//# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js.map //# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js.map
\ No newline at end of file
...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) { ...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1621,8 +1651,9 @@ let BACKEND; ...@@ -1621,8 +1651,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
...@@ -1228,11 +1228,40 @@ function getPathFromScript(chunkScript) { ...@@ -1228,11 +1228,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
var chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); var chunkUrl = chunkScript.src;
var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
var path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; var path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
var regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; var regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1313,7 +1342,7 @@ function instantiateModule(id, sourceType, sourceData) { ...@@ -1313,7 +1342,7 @@ function instantiateModule(id, sourceType, sourceData) {
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
function registerChunk(registration) { function registerChunk(registration) {
var chunkPath = getPathFromScript(registration[0]); var chunk = getChunkFromRegistration(registration[0]);
var runtimeParams; var runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
...@@ -1322,7 +1351,7 @@ function registerChunk(registration) { ...@@ -1322,7 +1351,7 @@ function registerChunk(registration) {
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories);
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try { try {
...@@ -1470,13 +1499,14 @@ var BACKEND; ...@@ -1470,13 +1499,14 @@ var BACKEND;
*/ var chunkResolvers = new Map(); */ var chunkResolvers = new Map();
(function() { (function() {
BACKEND = { BACKEND = {
registerChunk: function registerChunk(chunkPath, params) { registerChunk: function registerChunk(chunk, params) {
return _async_to_generator(function() { return _async_to_generator(function() {
var chunkUrl, resolver, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, otherChunkData, otherChunkPath, otherChunkUrl, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, moduleId; var chunkPath, chunkUrl, resolver, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, otherChunkData, otherChunkPath, otherChunkUrl, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, moduleId;
return _ts_generator(this, function(_state) { return _ts_generator(this, function(_state) {
switch(_state.label){ switch(_state.label){
case 0: case 0:
chunkUrl = getChunkRelativeUrl(chunkPath); chunkPath = getPathFromScript(chunk);
chunkUrl = getUrlFromScript(chunk);
resolver = getOrCreateResolver(chunkUrl); resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) { ...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1621,8 +1651,9 @@ let BACKEND; ...@@ -1621,8 +1651,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) { ...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1621,8 +1651,9 @@ let BACKEND; ...@@ -1621,8 +1651,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) { ...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1621,8 +1651,9 @@ let BACKEND; ...@@ -1621,8 +1651,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) { ...@@ -726,11 +726,40 @@ function getPathFromScript(chunkScript) {
if (typeof chunkScript === 'string') { if (typeof chunkScript === 'string') {
return chunkScript; return chunkScript;
} }
const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined' ? TURBOPACK_NEXT_CHUNK_URLS.pop() : chunkScript.getAttribute('src'); const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/**
* Return the ChunkUrl from a ChunkScript.
*/ function getUrlFromScript(chunk) {
if (typeof chunk === 'string') {
return getChunkRelativeUrl(chunk);
} else {
// This is already exactly what we want
return chunk.src;
}
}
/**
* Determine the chunk to register. Note that this function has side-effects!
*/ function getChunkFromRegistration(chunk) {
if (typeof chunk === 'string') {
return chunk;
} else if (!chunk) {
if (typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined') {
return {
src: TURBOPACK_NEXT_CHUNK_URLS.pop()
};
} else {
throw new Error('chunk path empty but not in a worker');
}
} else {
return {
src: chunk.getAttribute('src')
};
}
}
const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/;
/** /**
* Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment.
...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) { ...@@ -1564,21 +1593,22 @@ function createModuleHot(moduleId, hotData) {
runtimeChunkLists.add(chunkListPath); runtimeChunkLists.add(chunkListPath);
} }
function registerChunk(registration) { function registerChunk(registration) {
const chunkPath = getPathFromScript(registration[0]); const chunk = getChunkFromRegistration(registration[0]);
let runtimeParams; let runtimeParams;
// When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length // When bootstrapping we are passed a single runtimeParams object so we can distinguish purely based on length
if (registration.length === 2) { if (registration.length === 2) {
runtimeParams = registration[1]; runtimeParams = registration[1];
} else { } else {
let chunkPath = getPathFromScript(chunk);
runtimeParams = undefined; runtimeParams = undefined;
installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath)); installCompressedModuleFactories(registration, /* offset= */ 1, moduleFactories, (id)=>addModuleToChunk(id, chunkPath));
} }
return BACKEND.registerChunk(chunkPath, runtimeParams); return BACKEND.registerChunk(chunk, runtimeParams);
} }
/** /**
* Subscribes to chunk list updates from the update server and applies them. * Subscribes to chunk list updates from the update server and applies them.
*/ function registerChunkList(chunkList) { */ function registerChunkList(chunkList) {
const chunkListScript = chunkList.script; const chunkListScript = getChunkFromRegistration(chunkList.script);
const chunkListPath = getPathFromScript(chunkListScript); const chunkListPath = getPathFromScript(chunkListScript);
// The "chunk" is also registered to finish the loading in the backend // The "chunk" is also registered to finish the loading in the backend
BACKEND.registerChunk(chunkListPath); BACKEND.registerChunk(chunkListPath);
...@@ -1621,8 +1651,9 @@ let BACKEND; ...@@ -1621,8 +1651,9 @@ let BACKEND;
*/ const chunkResolvers = new Map(); */ const chunkResolvers = new Map();
(()=>{ (()=>{
BACKEND = { BACKEND = {
async registerChunk (chunkPath, params) { async registerChunk (chunk, params) {
const chunkUrl = getChunkRelativeUrl(chunkPath); let chunkPath = getPathFromScript(chunk);
let chunkUrl = getUrlFromScript(chunk);
const resolver = getOrCreateResolver(chunkUrl); const resolver = getOrCreateResolver(chunkUrl);
resolver.resolve(); resolver.resolve();
if (params == null) { if (params == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment