-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: Enable tree shaking in next.js #8523
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
8 Skipped Deployments
|
🟢 Turbopack Benchmark CI successful 🟢Thanks |
✅ This change can build |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this big change!
In the future to help make reviewing these PRs easier, it might be useful to squash some of the commits locally before force pushing or putting it up for review. Github (and Graphite) lists every commit in the conversation log, and it adds a lot of noise when there's 152 commits.
Reverts #8523 We need to revert this due to some changes in turbopack code
### Description I faced this bug while working on vercel/turborepo#8523. Tree shaking inevitably creates direct imports for let bindings, and when the LHS of `+=` is imported/exported, it triggers a bug. The problematic input file looks like ```js // Combined load times for loading client components let clientComponentLoadStart = 0 let clientComponentLoadTimes = 0 let clientComponentLoadCount = 0 export function wrapClientComponentLoader(ComponentMod: any) { if (!('performance' in globalThis)) { return ComponentMod.__next_app__ } return { require: (...args: any[]) => { const startTime = performance.now() if (clientComponentLoadStart === 0) { clientComponentLoadStart = startTime } try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.require(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, loadChunk: (...args: any[]) => { const startTime = performance.now() try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.loadChunk(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, } } export function getClientComponentLoaderMetrics( options: { reset?: boolean } = {} ) { const metrics = clientComponentLoadStart === 0 ? undefined : { clientComponentLoadStart, clientComponentLoadTimes, clientComponentLoadCount, } if (options.reset) { clientComponentLoadStart = 0 clientComponentLoadTimes = 0 clientComponentLoadCount = 0 } return metrics } ``` and it works if I apply this PR or I replace `clientComponentLoadTimes += performance.now() - startTime` with `clientComponentLoadTimes = clientComponentLoadTimes + performance.now() - startTime`. ### Testing Instructions Test references changed quite a lot.
### Description - next.js counterpart: #66689 ### Testing Instructions
Reverts vercel/turborepo#8523 We need to revert this due to some changes in turbopack code
### Description I faced this bug while working on vercel/turborepo#8523. Tree shaking inevitably creates direct imports for let bindings, and when the LHS of `+=` is imported/exported, it triggers a bug. The problematic input file looks like ```js // Combined load times for loading client components let clientComponentLoadStart = 0 let clientComponentLoadTimes = 0 let clientComponentLoadCount = 0 export function wrapClientComponentLoader(ComponentMod: any) { if (!('performance' in globalThis)) { return ComponentMod.__next_app__ } return { require: (...args: any[]) => { const startTime = performance.now() if (clientComponentLoadStart === 0) { clientComponentLoadStart = startTime } try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.require(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, loadChunk: (...args: any[]) => { const startTime = performance.now() try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.loadChunk(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, } } export function getClientComponentLoaderMetrics( options: { reset?: boolean } = {} ) { const metrics = clientComponentLoadStart === 0 ? undefined : { clientComponentLoadStart, clientComponentLoadTimes, clientComponentLoadCount, } if (options.reset) { clientComponentLoadStart = 0 clientComponentLoadTimes = 0 clientComponentLoadCount = 0 } return metrics } ``` and it works if I apply this PR or I replace `clientComponentLoadTimes += performance.now() - startTime` with `clientComponentLoadTimes = clientComponentLoadTimes + performance.now() - startTime`. ### Testing Instructions Test references changed quite a lot.
### Description - next.js counterpart: #66689 ### Testing Instructions
Reverts vercel/turborepo#8523 We need to revert this due to some changes in turbopack code
### Description I faced this bug while working on vercel/turborepo#8523. Tree shaking inevitably creates direct imports for let bindings, and when the LHS of `+=` is imported/exported, it triggers a bug. The problematic input file looks like ```js // Combined load times for loading client components let clientComponentLoadStart = 0 let clientComponentLoadTimes = 0 let clientComponentLoadCount = 0 export function wrapClientComponentLoader(ComponentMod: any) { if (!('performance' in globalThis)) { return ComponentMod.__next_app__ } return { require: (...args: any[]) => { const startTime = performance.now() if (clientComponentLoadStart === 0) { clientComponentLoadStart = startTime } try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.require(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, loadChunk: (...args: any[]) => { const startTime = performance.now() try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.loadChunk(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, } } export function getClientComponentLoaderMetrics( options: { reset?: boolean } = {} ) { const metrics = clientComponentLoadStart === 0 ? undefined : { clientComponentLoadStart, clientComponentLoadTimes, clientComponentLoadCount, } if (options.reset) { clientComponentLoadStart = 0 clientComponentLoadTimes = 0 clientComponentLoadCount = 0 } return metrics } ``` and it works if I apply this PR or I replace `clientComponentLoadTimes += performance.now() - startTime` with `clientComponentLoadTimes = clientComponentLoadTimes + performance.now() - startTime`. ### Testing Instructions Test references changed quite a lot.
### Description - next.js counterpart: #66689 ### Testing Instructions
Reverts vercel/turborepo#8523 We need to revert this due to some changes in turbopack code
### Description I faced this bug while working on vercel/turborepo#8523. Tree shaking inevitably creates direct imports for let bindings, and when the LHS of `+=` is imported/exported, it triggers a bug. The problematic input file looks like ```js // Combined load times for loading client components let clientComponentLoadStart = 0 let clientComponentLoadTimes = 0 let clientComponentLoadCount = 0 export function wrapClientComponentLoader(ComponentMod: any) { if (!('performance' in globalThis)) { return ComponentMod.__next_app__ } return { require: (...args: any[]) => { const startTime = performance.now() if (clientComponentLoadStart === 0) { clientComponentLoadStart = startTime } try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.require(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, loadChunk: (...args: any[]) => { const startTime = performance.now() try { clientComponentLoadCount += 1 return ComponentMod.__next_app__.loadChunk(...args) } finally { clientComponentLoadTimes += performance.now() - startTime } }, } } export function getClientComponentLoaderMetrics( options: { reset?: boolean } = {} ) { const metrics = clientComponentLoadStart === 0 ? undefined : { clientComponentLoadStart, clientComponentLoadTimes, clientComponentLoadCount, } if (options.reset) { clientComponentLoadStart = 0 clientComponentLoadTimes = 0 clientComponentLoadCount = 0 } return metrics } ``` and it works if I apply this PR or I replace `clientComponentLoadTimes += performance.now() - startTime` with `clientComponentLoadTimes = clientComponentLoadTimes + performance.now() - startTime`. ### Testing Instructions Test references changed quite a lot.
### Description - next.js counterpart: #66689 ### Testing Instructions
Reverts vercel/turborepo#8523 We need to revert this due to some changes in turbopack code
Description
I'll debug/fix tree shaking implementation with this PR
Testing Instructions