[WIP]feat(pack): downgrade turbopack runtime insert js code#2707
[WIP]feat(pack): downgrade turbopack runtime insert js code#2707fireairforce wants to merge 1 commit intonextfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the compatibility of Turbopack's runtime code insertion by downgrading the method used to insert JavaScript code. The changes involve modifying the generated output files to use a more universally compatible approach for accessing the global scope and converting arrow functions to standard functions. This ensures that the generated code works correctly in a wider range of environments. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request appears to downgrade the JavaScript features used in the Turbopack runtime and generated chunks, likely to improve compatibility with older environments. This includes replacing globalThis with a polyfill, const/let with var, arrow functions with function expressions, and for...of loops with traditional for loops. The snapshot tests have been updated to reflect these changes.
My main feedback is regarding the implementation of the globalThis polyfill, which is repeated multiple times in some generated files. This increases bundle size and reduces readability. I've left a specific comment with a suggestion for improvement.
| @@ -1,15 +1,15 @@ | |||
| (globalThis["utooChunk_async_chunk_test"] || (globalThis["utooChunk_async_chunk_test"] = [])).push([typeof document === "object" ? document.currentScript : undefined, | |||
| 192, ((__turbopack_context__) => { | |||
| ((typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : (typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {}))))["utooChunk_async_chunk_test"] || ((typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : (typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {}))))["utooChunk_async_chunk_test"] = [])).push([typeof document === "object" ? document.currentScript : undefined, | |||
There was a problem hiding this comment.
| @@ -1,17 +1,19 @@ | |||
| (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ | |||
| ((typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : (typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {}))))["TURBOPACK"] || ((typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : (typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {}))))["TURBOPACK"] = [])).push([ | |||
There was a problem hiding this comment.
The expression to find the global object is repeated, making the code verbose and increasing file size. It would be cleaner to define a variable for the global object and reuse it, similar to how __turbopack_global__ is used later in this file. This would improve readability and reduce the bundle size.
| try { | ||
| for (const registration of chunksToRegister) { | ||
| const runtimeParams = registration.length === 2 ? registration[1] : null; | ||
| for (var i = 0; i < chunksToRegister.length; i++) { |
There was a problem hiding this comment.
Using a classic for loop with an index is a valid way to downgrade from a for...of loop for older environment compatibility. However, for iterating over arrays, a forEach loop would also be compatible and is often more readable. Since chunksToRegister is an array, you could consider using chunksToRegister.forEach(function(registration) { ... }); here for better readability, which is already used elsewhere in the codebase.
📊 Performance Benchmark Report (with-antd)Utoopack Performance ReportReport ID: Executive Summary
Build Phase TimelineShows when each build phase is active and how much CPU it consumes.
Workload Distribution by Diagnostic Tier
Top 20 Tasks by Self-TimeSelf-time is the exclusive duration: time spent in the task itself, not in sub-tasks.
Critical Path AnalysisThe longest sequential dependency chains that determine wall-clock time.
Batching CandidatesHigh-volume tasks dominated by a single parent. If the parent can batch them,
Duration Distribution
Action Items
Report generated by Utoopack Performance Analysis Agent |
Summary
follow: #2703
ref pr: utooland/next.js#123
Test Plan
snapshot updated