Unverified Commit 7577fa3c authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Fix Turbopack worker chunk loading with asset prefix (#96636)

## Summary

- propagate the effective worker asset prefix through the worker
bootstrap so runtime chunk registration and loading use the same base
path
- verify workers execute with both explicit and empty
`turbopackWorkerAssetPrefix` overrides
- add coverage for the Resvg WASM worker reproduction

Fixes #96613

## Verification

- `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-turbo
test/e2e/turbopack-worker-asset-prefix/turbopack-worker-asset-prefix.test.ts`
- `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-turbo
test/e2e/turbopack-worker-asset-prefix/turbopack-worker-asset-prefix.test.ts`
- Resvg WASM worker test in production and development Turbopack
- focused `turbopack-tests` worker and ignore-comments snapshots
- `pnpm swc-build-native`
- Full `pnpm build-all` did not complete locally because of unrelated
existing `httpxy` and proxy-request type errors

<!-- NEXT_JS_LLM -->

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent 50eacb5b
import { Resvg, initWasm } from '@resvg/resvg-wasm'
type Props = {
svg: string
width: number
}
self.onmessage = async (event: MessageEvent<Props>) => {
const { svg, width } = event.data
try {
await initWasm(fetch('/wasms/resvg.wasm'))
const renderer = new Resvg(svg, {
fitTo: {
mode: 'width',
value: Math.round(width),
},
})
const pngBuffer = renderer.render().asPng()
const blob = new Blob([new Uint8Array(pngBuffer)], {
type: 'image/png',
})
self.postMessage({ success: true, blob })
} catch (error) {
self.postMessage({
success: false,
error: error instanceof Error ? error.message : String(error),
})
}
}
'use client'
import { useState } from 'react'
import { svgToPngFromWebWorker } from './svg-to-png-from-web-worker'
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="4">
<rect width="8" height="4" fill="red" />
</svg>
`
export default function ResvgWorkerPage() {
const [result, setResult] = useState({
state: 'default',
type: 'default',
dimensions: 'default',
size: '0',
})
return (
<main>
<button
onClick={async () => {
try {
const blob = await svgToPngFromWebWorker(svg, 8, 2)
const image = await createImageBitmap(blob)
setResult({
state: 'success',
type: blob.type,
dimensions: `${image.width}x${image.height}`,
size: String(blob.size),
})
image.close()
} catch (error) {
setResult((current) => ({
...current,
state: `error:${
error instanceof Error ? error.message : String(error)
}`,
}))
}
}}
>
Render SVG in worker
</button>
<p id="worker-state">{result.state}</p>
<p id="png-type">{result.type}</p>
<p id="png-dimensions">{result.dimensions}</p>
<p id="png-size">{result.size}</p>
</main>
)
}
export async function svgToPngFromWebWorker(
svg: string,
width: number,
multiplier?: number
): Promise<Blob> {
const worker = new Worker(new URL('../resvg-worker.ts', import.meta.url))
try {
return await new Promise<Blob>((resolve, reject) => {
worker.onmessage = (event) => {
if (event.data.success) {
resolve(event.data.blob)
} else {
reject(event.data.error)
}
}
worker.postMessage({
svg,
width: width * (multiplier ?? devicePixelRatio),
})
})
} finally {
worker.terminate()
}
}
import { isNextDeploy, isNextStart, nextTestSetup } from 'e2e-utils'
import { FileRef, isNextDeploy, isNextStart, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import { join } from 'path'
import { Page } from 'playwright'
describe('app dir - workers', () => {
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
files: {
app: new FileRef(join(__dirname, 'app')),
public: new FileRef(join(__dirname, 'public')),
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
'public/wasms/resvg.wasm': new FileRef(
require.resolve('next/dist/compiled/@vercel/og/resvg.wasm')
),
},
dependencies: {
'@resvg/resvg-wasm': '2.4.0',
},
env: {
NEXT_DEPLOYMENT_ID: isNextStart ? 'test-deployment-id' : undefined,
},
......@@ -117,6 +128,24 @@ describe('app dir - workers', () => {
)
})
it('should support rendering an SVG with a WASM package in a worker', async () => {
const browser = await next.browser('/resvg', {
beforePageLoad,
})
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
await browser.elementByCss('button').click()
await retry(async () => {
expect(await browser.elementByCss('#worker-state').text()).toBe('success')
expect(await browser.elementByCss('#png-type').text()).toBe('image/png')
expect(await browser.elementByCss('#png-dimensions').text()).toBe('16x8')
expect(
Number(await browser.elementByCss('#png-size').text())
).toBeGreaterThan(0)
})
})
it('should support shared workers', async () => {
if (!isTurbopack) {
// webpack requires a magic attribute for shared workers to function
......
......@@ -8,6 +8,7 @@ export default function ClientComponent() {
const [pageOrigin, setPageOrigin] = useState<string>(NONE)
const [workerCtorUrl, setWorkerCtorUrl] = useState<string>(NONE)
const [workerCtorError, setWorkerCtorError] = useState<string>(NONE)
const [workerReply, setWorkerReply] = useState<string>(NONE)
useEffect(() => {
setPageOrigin(window.location.origin)
......@@ -31,16 +32,22 @@ export default function ClientComponent() {
}
}
let worker: Worker | undefined
try {
// Trigger the turbopack `new Worker(new URL(..., import.meta.url))`
// pattern. Result is intercepted by the patched Worker above.
new Worker(new URL('./worker.ts', import.meta.url))
worker = new Worker(new URL('./worker.ts', import.meta.url))
worker.onmessage = (event) => {
setWorkerReply(event.data)
}
worker.postMessage('ping')
} catch {
// Already captured by the patched constructor; React state will
// reflect it on the next render.
}
;(window as any).Worker = OriginalWorker
return () => worker?.terminate()
}, [])
return (
......@@ -51,6 +58,8 @@ export default function ClientComponent() {
<pre id="worker-ctor-url">{workerCtorUrl}</pre>
<p>Worker constructor error (if any):</p>
<pre id="worker-ctor-error">{workerCtorError}</pre>
<p>Worker reply:</p>
<pre id="worker-reply">{workerReply}</pre>
</>
)
}
// Post back the worker's own origin so the main thread can verify whether the
// worker entrypoint was loaded same-origin or cross-origin.
self.postMessage(self.location.origin)
self.onmessage = (event: MessageEvent<string>) => {
self.postMessage(`pong: ${event.data}`)
}
export {}
......@@ -103,6 +103,11 @@ describeTurbopack('turbopack-worker-asset-prefix', () => {
const error = await browser.elementByCss('#worker-ctor-error').text()
expect(error).toBe('(none)')
await retry(async () => {
const reply = await browser.elementByCss('#worker-reply').text()
expect(reply).toBe('pong: ping')
})
})
})
......@@ -148,5 +153,14 @@ describeTurbopack('turbopack-worker-asset-prefix', () => {
const error = await browser.elementByCss('#worker-ctor-error').text()
expect(error).toBe('(none)')
})
it('executes the worker and receives a reply', async () => {
const browser = await next.browser('/')
await retry(async () => {
const reply = await browser.elementByCss('#worker-reply').text()
expect(reply).toBe('pong: ping')
})
})
})
})
......@@ -21,7 +21,7 @@ use crate::BrowserChunkingContext;
/// A pre-compiled worker entrypoint that bootstraps workers by reading config from URL params.
///
/// The worker receives a JSON array via URL params of the following structure:
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...forwarded_global_values]`
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...forwarded_global_values]`
#[turbo_tasks::value(shared)]
#[derive(ValueToString)]
#[value_to_string("Ecmascript Browser Worker Entrypoint")]
......@@ -148,7 +148,7 @@ impl GenerateSourceMap for EcmascriptBrowserWorkerEntrypoint {
/// Generates the worker bootstrap code as inline JavaScript.
///
/// The worker receives a JSON array via URL params of the following structure:
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...forwarded_global_values]`
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...forwarded_global_values]`
fn generate_worker_bootstrap_code(
forwarded_globals: &[RcStr],
shared_runtime: bool,
......@@ -156,14 +156,16 @@ fn generate_worker_bootstrap_code(
let mut code: CodeBuilder = CodeBuilder::default();
// Generate the Object.assign properties for forwarded globals
// params[0] = chunk URLs, params[1] = ASSET_SUFFIX, params[2+] = forwarded globals
// params[0] = chunk URLs, params[1] = ASSET_SUFFIX,
// params[2] = WORKER_CHUNK_BASE_PATH, params[3+] = forwarded globals
let mut global_assignments = vec![
"TURBOPACK_NEXT_CHUNK_URLS: chunkUrls".to_string(),
"TURBOPACK_ASSET_SUFFIX: param(1)".to_string(),
"TURBOPACK_CHUNK_BASE_PATH: param(2)".to_string(),
];
for (i, name) in forwarded_globals.iter().enumerate() {
// Forwarded globals start at params[2]
global_assignments.push(format!("{name}: param({n})", n = i + 2));
// Forwarded globals start at params[3]
global_assignments.push(format!("{name}: param({n})", n = i + 3));
}
let globals_js = global_assignments.join(",\n ");
......
......@@ -17,6 +17,9 @@ declare var TURBOPACK_ASSET_SUFFIX: string
// can't be detected via `document.currentScript`. Note it's stored in reversed
// order to use `push` and `pop`
declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined
// Used in WebWorkers to override the regular chunk base path with the base
// used for the worker entrypoint and its initial chunks.
declare var TURBOPACK_CHUNK_BASE_PATH: string | undefined
// Injected by rust code
declare var CHUNK_BASE_PATH: string
......@@ -34,6 +37,11 @@ interface TurbopackBrowserBaseContext<M> extends TurbopackBaseContext<M> {
const browserContextPrototype =
Context.prototype as TurbopackBrowserBaseContext<unknown>
const RUNTIME_CHUNK_BASE_PATH =
typeof TURBOPACK_CHUNK_BASE_PATH === 'string'
? TURBOPACK_CHUNK_BASE_PATH
: CHUNK_BASE_PATH
// Provided by build or dev base
declare function instantiateModule(
id: ModuleId,
......@@ -341,7 +349,9 @@ function loadChunkByUrlInternal(
function chunkUrlToPath(chunkUrl: ChunkUrl): ChunkPath {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
return (
src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src
src.startsWith(RUNTIME_CHUNK_BASE_PATH)
? src.slice(RUNTIME_CHUNK_BASE_PATH.length)
: src
) as ChunkPath
}
......@@ -486,7 +496,7 @@ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/
*/
function getChunkRelativeUrl(
chunkPath: ChunkPath | ChunkListPath,
basePath: string = CHUNK_BASE_PATH
basePath: string = RUNTIME_CHUNK_BASE_PATH
): ChunkUrl {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath)
......@@ -497,7 +507,7 @@ function getChunkRelativeUrl(
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH as ChunkBasePath
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH as ChunkBasePath
browserContextPrototype.X = ASSET_SUFFIX as AssetSuffix
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
......@@ -519,8 +529,8 @@ function getPathFromScript(
}
const chunkUrl = chunkScript.src!
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
const path = src.startsWith(CHUNK_BASE_PATH)
? src.slice(CHUNK_BASE_PATH.length)
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH)
? src.slice(RUNTIME_CHUNK_BASE_PATH.length)
: src
return path as ChunkPath | ChunkListPath
}
......
......@@ -130,7 +130,7 @@ let DEV_BACKEND: DevRuntimeBackend
function _eval({ code, url, map }: EcmascriptModuleEntry): ModuleFactory {
code += `\n\n//# sourceURL=${encodeURI(
location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX
location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX
)}`
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(
......
......@@ -32,7 +32,7 @@ type WorkerChunkData = string | { path: string }
* which module chunks to load and which module to run as the entry point.
*
* The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]`
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
*
* @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk
......@@ -62,7 +62,11 @@ function createWorker(
)
)
.reverse()
const params: unknown[] = [chunkUrls, __turbopack_chunk_asset_suffix__]
const params: unknown[] = [
chunkUrls,
__turbopack_chunk_asset_suffix__,
workerBasePath,
]
const globals = _TURBOPACK_WORKER_FORWARDED_GLOBALS_
for (let i = 0; i < globals.length; i++) {
params.push((globalThis as Record<string, unknown>)[globals[i]])
......
;!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]="8be33d93-70f0-5795-483a-8e4593e9e07e")}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]="f34f4684-6127-f0e7-0897-822ba1e1eea2")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1i9t_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js",
{"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvs.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
......@@ -684,6 +684,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -863,7 +864,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -955,14 +956,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -973,7 +974,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2463,7 +2464,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......@@ -2481,5 +2482,5 @@ chunkListsToRegister.forEach(registerChunkList);
})();
//# debugId=8be33d93-70f0-5795-483a-8e4593e9e07e
//# debugId=f34f4684-6127-f0e7-0897-822ba1e1eea2
//# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map
\ No newline at end of file
......@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1)
TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
});
if (chunkUrls.length > 0) {
......
......@@ -73,7 +73,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point.
*
* The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]`
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
*
* @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk
......@@ -89,7 +89,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [
chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X
/*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
];
const globals = [];
for(let i = 0; i < globals.length; i++){
......
......@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......
......@@ -958,6 +958,7 @@ function _ts_generator(thisArg, body) {
}
}
var browserContextPrototype = Context.prototype;
var RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
var moduleFactories = new Map();
contextPrototype.M = moduleFactories;
var availableModules = new Map();
......@@ -1237,7 +1238,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -1350,14 +1351,14 @@ browserContextPrototype.q = exportUrl;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath) {
var basePath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : CHUNK_BASE_PATH;
var basePath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : RUNTIME_CHUNK_BASE_PATH;
// Most chunk paths need no escaping.
var encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -1368,7 +1369,7 @@ function getPathFromScript(chunkScript) {
}
var chunkUrl = chunkScript.src;
var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
var path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
var path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......
......@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1)
TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
});
if (chunkUrls.length > 0) {
......
......@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......
......@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......
......@@ -49,7 +49,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point.
*
* The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]`
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
*
* @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk
......@@ -65,7 +65,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [
chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X
/*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
];
const globals = [];
for(let i = 0; i < globals.length; i++){
......
......@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1)
TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
});
if (chunkUrls.length > 0) {
......
......@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......
......@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map();
contextPrototype.M = moduleFactories;
const availableModules = new Map();
......@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
}
/**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
......@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/**
* Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) {
*/ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
}
// Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH;
browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
......@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
}
const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path;
}
/**
......@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
}
})();
function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875
......
......@@ -48,7 +48,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point.
*
* The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]`
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
*
* @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk
......@@ -64,7 +64,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [
chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X
/*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
];
const globals = [];
for(let i = 0; i < globals.length; i++){
......
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