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 significantly enhances the compatibility of Turbopack's generated JavaScript code by downgrading certain modern syntax features and implementing a more resilient global object detection mechanism. The primary goal is to ensure that applications built with Turbopack function correctly across a wider array of client environments, including older or less capable devices, by avoiding reliance on newer JavaScript features. 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 aims to improve compatibility with older devices by downgrading the generated JavaScript code. The changes systematically replace modern JavaScript features like const, arrow functions, and for...of loops with their older equivalents (var, function expressions, and traditional for loops). A fallback for globalThis is also introduced to support various JavaScript environments. The changes are consistent and effectively achieve the stated goal. My review includes a suggestion to refactor a duplicated constant to improve code maintainability.
| pub const GLOBAL_THIS_FALLBACK_EXPR: &str = | ||
| "typeof globalThis !== \"undefined\" ? globalThis : (typeof self !== \"undefined\" ? self : (typeof window !== \"undefined\" ? window : (typeof global !== \"undefined\" ? global : {})))"; |
There was a problem hiding this comment.
This constant is a duplicate of one defined in turbopack-ecmascript-runtime/src/browser_runtime.rs. To avoid duplication, this definition should be removed. The constant in the other crate can be made public and used here instead. The other files in this crate that use this constant will need to update their imports to something like use turbopack_ecmascript_runtime::browser_runtime::GLOBAL_THIS_FALLBACK_EXPR;.
| const GLOBAL_THIS_FALLBACK_EXPR: &str = | ||
| "typeof globalThis !== \"undefined\" ? globalThis : (typeof self !== \"undefined\" ? self : (typeof window !== \"undefined\" ? window : (typeof global !== \"undefined\" ? global : {})))"; |
There was a problem hiding this comment.
To avoid code duplication, this constant could be made public (pub const) so it can be reused in the turbopack-browser crate. A duplicate of this constant is currently being added in turbopack-browser/src/chunking_context.rs. By making this one public, the other one can be removed.
| const GLOBAL_THIS_FALLBACK_EXPR: &str = | |
| "typeof globalThis !== \"undefined\" ? globalThis : (typeof self !== \"undefined\" ? self : (typeof window !== \"undefined\" ? window : (typeof global !== \"undefined\" ? global : {})))"; | |
| pub const GLOBAL_THIS_FALLBACK_EXPR: &str = | |
| "typeof globalThis !== \"undefined\" ? globalThis : (typeof self !== \"undefined\" ? self : (typeof window !== \"undefined\" ? window : (typeof global !== \"undefined\" ? global : {})))"; |
|
|
||
| const __chunk__ = (() => {{ | ||
| if (!Array.isArray(globalThis["{chunk_loading_global}"])) {{ | ||
| var __chunk__ = (function() {{ |
There was a problem hiding this comment.
为啥选择直接改 runtime 源码?这样如果想打包 es6 都做不到,而且同步上游代码也很烦啊。
There was a problem hiding this comment.
这里比较麻烦的地方一个在于:
- module factory 全是 arrow function,可能会有体积影响
- 这里还有 async / await 片段(async module load)


downgrade insert js code to avoid low devices.