Unverified Commit 013908ab authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Register only canonical IDs for flat-export groups

Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
parent 6466487e
...@@ -1408,12 +1408,17 @@ impl EcmascriptModuleContent { ...@@ -1408,12 +1408,17 @@ impl EcmascriptModuleContent {
}; };
let first_entry = entry_points.first().unwrap().0; let first_entry = entry_points.first().unwrap().0;
let additional_ids = modules let additional_ids = if flat_exports {
// All imports of a flat group use its canonical entry, which is also the chunk
// item's ID. The other exposed members do not need factory aliases.
SmallVec::new()
} else {
modules
.keys() .keys()
// Additionally set this module factory for all modules that are exposed. The whole // Additionally set this module factory for all modules that are exposed. The
// group might be imported via a different entry import in different chunks (we only // whole group might be imported via a different entry import in different
// ensure that the modules are in the same order, not that they form a subgraph that // chunks (we only ensure that the modules are in the same order, not that they
// is always imported from the same root module). // form a subgraph that is always imported from the same root module).
// //
// Also skip the first entry, which is the name of the chunk item. // Also skip the first entry, which is the name of the chunk item.
.filter(|m| { .filter(|m| {
...@@ -1423,7 +1428,8 @@ impl EcmascriptModuleContent { ...@@ -1423,7 +1428,8 @@ impl EcmascriptModuleContent {
.map(|m| m.chunk_item_id(*options.chunking_context)) .map(|m| m.chunk_item_id(*options.chunking_context))
.try_join() .try_join()
.await? .await?
.into(); .into()
};
emit_content(content, additional_ids) emit_content(content, additional_ids)
.instrument(tracing::info_span!("emit code")) .instrument(tracing::info_span!("emit code"))
......
...@@ -48,4 +48,15 @@ it('should be correct across a chunk boundary with scope hoisting enabled', asyn ...@@ -48,4 +48,15 @@ it('should be correct across a chunk boundary with scope hoisting enabled', asyn
expect(fromLazy()).toBe( expect(fromLazy()).toBe(
'shared-1/shared-fn/second-1/shared-short/second-short/1' 'shared-1/shared-fn/second-1/shared-short/second-short/1'
) )
// Another chunk reads and updates the noncanonical member of the same shared group. All of its
// imports must use the one registered factory ID, and updates must remain visible in both chunks.
const { readAndIncrement } = await import(
/* turbopackExports: ["readAndIncrement"] */ './lazy-second'
)
expect(readAndIncrement()).toEqual(['shared-1', 1, 2])
expect(liveValue).toBe(2)
expect(fromLazy()).toBe(
'shared-1/shared-fn/second-1/shared-short/second-short/2'
)
}) })
// Keep both members in the shared group while reading and updating the noncanonical member.
import { someLongExportName } from './shared'
import { liveValue, increment } from './second'
export function readAndIncrement() {
const before = liveValue
increment()
return [someLongExportName, before, liveValue]
}
(()=>{"use strict";(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/0_9x_turbopack-tests_tests_snapshot_mangle-exports_flat-hoisted_input_19v7j-mslz9_y._.js", (()=>{"use strict";(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/0_9x_turbopack-tests_tests_snapshot_mangle-exports_flat-hoisted_input_19v7j-mslz9_y._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/first.js [test] (ecmascript)", "[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/second.js [test] (ecmascript)", "[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/first.js [test] (ecmascript)", ((__turbopack_context__) => {
((__turbopack_context__) => {
"use strict"; "use strict";
__turbopack_context__.s([ __turbopack_context__.s([
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
"version": 3, "version": 3,
"sources": [], "sources": [],
"sections": [ "sections": [
{"offset": {"line": 5, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/first.js","turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/second.js"],"sourcesContent":["export const sameLongExportName = 'first'\nexport const a = 'first-short'\n","export const sameLongExportName = 'second'\nexport const a = 'second-short'\n"],"names":["sameLongExportName","a"],"mappings":";;;;;;;;;;;;AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,IAAI;;;ACDV,MAAMD,sBAAqB;AAC3B,MAAM,KAAI"}}, {"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/first.js","turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/second.js"],"sourcesContent":["export const sameLongExportName = 'first'\nexport const a = 'first-short'\n","export const sameLongExportName = 'second'\nexport const a = 'second-short'\n"],"names":["sameLongExportName","a"],"mappings":";;;;;;;;;;;;AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,IAAI;;;ACDV,MAAMD,sBAAqB;AAC3B,MAAM,KAAI"}},
{"offset": {"line": 27, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/index.js"],"sourcesContent":["import { sameLongExportName as first, a as firstShort } from './first'\nimport { sameLongExportName as second, a as secondShort } from './second'\n\nconsole.log(first, second, firstShort, secondShort)\nimport('./lazy').then(({ read }) => console.log(read()))\n"],"names":["console","log","then","read"],"mappings":"AAAA;;;AAGAA,QAAQC,GAAG,CAAC,uNAAK,EAAE,uNAAM,EAAE,uNAAU,EAAE,uNAAW;AAClD,iKAAiBC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKH,QAAQC,GAAG,CAACE"}}] {"offset": {"line": 26, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/mangle-exports/flat-hoisted/input/index.js"],"sourcesContent":["import { sameLongExportName as first, a as firstShort } from './first'\nimport { sameLongExportName as second, a as secondShort } from './second'\n\nconsole.log(first, second, firstShort, secondShort)\nimport('./lazy').then(({ read }) => console.log(read()))\n"],"names":["console","log","then","read"],"mappings":"AAAA;;;AAGAA,QAAQC,GAAG,CAAC,uNAAK,EAAE,uNAAM,EAAE,uNAAU,EAAE,uNAAW;AAClD,iKAAiBC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKH,QAAQC,GAAG,CAACE"}}]
} }
\ No newline at end of file
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