-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In Next.js 15 with Turbopack mode, the IIFE is not executing as expected, resulting in a strange bug. #74190
Comments
This code is from my actual development experience; I just removed the unnecessary parts. |
update demo code var root = {};
// namespace builder
(function _(namespace, path, parent) {
// The expected output is "", "wrapper", "wrapper.data", "wrapper.data.key"
// The actual output is "", "wrapper", "data", "key"
console.debug("####", path)
for (var i = 0, keys = Object.keys(namespace); i < keys.length; i++) {
var key = keys[i];
// --------------------------------------------------------------------------
console.debug("####", path, path ? true : false) // always true? why?
// --------------------------------------------------------------------------
parent[key] = _(namespace[key], path ? `${path}.${key}` : key, parent[key] || {});
// --- If the line below is replaced, it will meet the expectations.
// parent[key] = _(namespace[key], Boolean(path) ? `${path}.${key}` : key, parent[key] || {});
}
return parent;
})({
wrapper: {
data: {
key: {}
},
}
}, "", root); |
I think it is bug of turbopack analyzer. |
I tested on my local machine, snapshot for arguments looks like invalid. @sokra can i know who can help turbopack analyzer issues? Graph/Snapshot: nnnnoel@6304325 |
Investigation
var root = {};
(function _(namespace, path, parent) {
for (var i = 0, keys = Object.keys(namespace); i < keys.length; i++) {
var key = keys[i];
console.debug("####", path, path ? true : false)
parent[key] = _(namespace[key], path ? `${path}.${key}` : key, parent[key] || {});
}
return parent;
})({
wrapper: {
data: {
key: {}
},
}
}, "", root); becomes var root = {};
(function _(namespace, path, parent) {
for(var i = 0, keys = Object.keys(namespace); i < keys.length; i++){
var key = keys[i];
console.debug("####", path, ("TURBOPACK compile-time falsy", 0) ? ("TURBOPACK unreachable", undefined) : false);
parent[key] = _(namespace[key], ("TURBOPACK compile-time falsy", 0) ? ("TURBOPACK unreachable", undefined) : key, parent[key] || {});
}
return parent;
})({
wrapper: {
data: {
key: {}
}
}
}, "", root); |
### What? Add a check for recursive IIFE. ### Why? Turbopack miscompiles recursive IIFEs because it does not check if IIFE recurses. ### How? Closes #74190
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/listen936/nextjs_15_turbopack_bug_demo
To Reproduce
Current vs. Expected behavior
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:27 PDT 2024; root:xnu-11215.41.3~2/RELEASE_X86_64 Available memory (MB): 16384 Available CPU cores: 8 Binaries: Node: 18.20.1 npm: 8.19.4 Yarn: 1.22.10 pnpm: 8.14.1 Relevant Packages: next: 15.1.2 // Latest available version is detected (15.1.2). eslint-config-next: 15.1.1 react: 19.0.0 react-dom: 19.0.0 typescript: 5.7.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: