fix(turbopack): prevent double-encoding of WASM fetch URLs when deployment suffix already present#92369
fix(turbopack): prevent double-encoding of WASM fetch URLs when deployment suffix already present#92369sleitor wants to merge 2 commits intovercel:canaryfrom
Conversation
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Merging this PR will degrade performance by 3.31%
Performance Changes
Comparing Footnotes
|
|
Could you add this to the test case in test/production/deployment-id-handling/deployment-id-handling.test.ts ? |
|
Done — added in commit 6e8ec0f:
The test will catch the regression described in the issue — before the fix, |
|
The CodSpeed 3.31% regression on This is not a regression in WASM loading performance at runtime — the fix is purely in the string manipulation logic of The alternative would be a compile-time fix in the Rust code that prevents |
…FFIX already present When a WASM module exports its path via `__turbopack_export_url__` (.q()), the exported value already has ASSET_SUFFIX (`?dpl=xxx`) appended. When the loader later calls `fetchWebAssembly(wasmChunkPath)`, which in turn calls `getChunkRelativeUrl(wasmChunkPath)`, the function splits by '/' and calls `encodeURIComponent` on each segment — encoding the '?' to '%3F' — then appends ASSET_SUFFIX a second time. This results in a URL like: /_next/static/chunks/xxx.wasm%3Fdpl%3Ddpl_xxx?dpl=dpl_xxx instead of the expected: /_next/static/chunks/xxx.wasm?dpl=dpl_xxx Fix: in `getChunkRelativeUrl`, detect if chunkPath already contains a query string and, if so, separate it from the path before encoding, then use the existing query string as the suffix instead of appending ASSET_SUFFIX again. JS/CSS chunks are unaffected because they load via `<script>`/`<link>` tags where the src is set directly from a ChunkUrl, not through this path. Regression introduced in 16.2.0 (vercel#88828). Fixes vercel#92356. Update turbopack snapshot tests to reflect new `getChunkRelativeUrl` impl. # Conflicts: # turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map # turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_dev_runtime/output/0_9x_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_17smy-b.js.map # turbopack/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/0_9x_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_04jskxh.js.map # turbopack/crates/turbopack-tests/tests/snapshot/workers/basic/output/1do3_crates_turbopack-tests_tests_snapshot_workers_basic_input_index_09-gc7x.js.map # turbopack/crates/turbopack-tests/tests/snapshot/workers/basic/output/1do3_crates_turbopack-tests_tests_snapshot_workers_basic_input_worker_0yr5fg0.js.map # turbopack/crates/turbopack-tests/tests/snapshot/workers/shared/output/1do3_crates_turbopack-tests_tests_snapshot_workers_shared_input_index_0arnewp.js.map # turbopack/crates/turbopack-tests/tests/snapshot/workers/shared/output/1do3_crates_turbopack-tests_tests_snapshot_workers_shared_input_worker_1xw116u.js.map
# Conflicts: # test/production/deployment-id-handling/deployment-id-handling.test.ts
What?
Fixes #92356 (regression from #88828, introduced in 16.2.0).
Why?
When a WASM module exports its path via
__turbopack_export_url__(.q()), the exported value already has ASSET_SUFFIX (?dpl=xxx) appended. When the loader later callsfetchWebAssembly(wasmChunkPath), which callsgetChunkRelativeUrl(wasmChunkPath), the function:/— the last segment now contains?dpl=xxxencodeURIComponenton each segment — encoding?→%3FASSET_SUFFIXagainResult:
/_next/static/chunks/xxx.wasm%3Fdpl%3Ddpl_xxx?dpl=dpl_xxx→ 404JS and CSS chunks are unaffected because they are loaded via
<script>/<link>tags where the URL is set directly, not throughgetChunkRelativeUrl.How?
In
getChunkRelativeUrl, detect ifchunkPathalready contains a query string. If so, split the path from the query before encoding, and use the existing query string as the suffix instead of appendingASSET_SUFFIXa second time. If no query string is present (normal JS/CSS chunks), behaviour is unchanged.Also updates all affected snapshot test files to reflect the new implementation.
Fixes #92356