[turbopack] Raise registration calls in hoisted modules to the top (#96697)
Closes https://github.com/vercel/next.js/issues/96648, take a look at code like this: <img width="1414" height="1336" alt="image" src="https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422" /> Line 26 of scope-hoisting group A enters scope-hoisting group B, then on line 95 we re-enter scope-hoisting group A. Because our first execution of group A hadn't reached Line 29 yet to register schemas.js (which B depends on schemas.js). On non-scope hoisted modules with cycles we already raise the module registration call to the start of the factory. But when we scope hoist, we lose that. This PR changes it so we do the registration at the start of the scope hoisted module Before: ```javascript "shared.js", "library/src/schemas.js", "library/src/index.js <export * as z>", ((__turbopack_context__) => { "use strict"; // MERGED MODULE: shared.js ; var …errors = __turbopack_context__.i("library/src/errors.js"); // MERGED MODULE: library/src/index.js <export * as z> ; // MERGED MODULE: library/src/index.js ; var …index_locals = __turbopack_context__.i("library/src/index.js <locals>"); // ← leaves the group // MERGED MODULE: library/src/schemas.js ; __turbopack_context__.s([ // ← schemas registers HERE, too late "any", ()=>any, "anyBase", ()=>anyBase, "instance", ()=>instance, "instanceFromClosure", ()=>instanceFromClosure ], "library/src/schemas.js"); var …iso = __turbopack_context__.i("library/src/iso.js"); ``` After: ```javascript "shared.js", "library/src/schemas.js", "library/src/index.js <export * as z>", ((__turbopack_context__) => { "use strict"; __turbopack_context__.s([ // ← raised to the top of the merged module "any", ()=>any, "anyBase", ()=>anyBase, "instance", ()=>instance, "instanceFromClosure", ()=>instanceFromClosure ], "library/src/schemas.js"); // MERGED MODULE: shared.js ; var …errors = __turbopack_context__.i("library/src/errors.js"); // MERGED MODULE: library/src/index.js <export * as z> ; // MERGED MODULE: library/src/index.js ; var …index_locals = __turbopack_context__.i("library/src/index.js <locals>"); // ← re-entry is safe // MERGED MODULE: library/src/schemas.js ; var …iso = __turbopack_context__.i("library/src/iso.js"); ```
Showing
Please
register
or
sign in
to comment