-
Notifications
You must be signed in to change notification settings - Fork 0
feat(turbopack): runtime code support publicPath runtime #63
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
Conversation
Summary of ChangesHello @fireairforce, 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 enhances Turbopack's runtime by introducing support for a dynamic Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
这个 PR 为 Turbopack 的浏览器运行时添加了对运行时 publicPath 的支持,做得很好。新的 getRuntimeChunkBasePath 函数逻辑清晰,并且在 getChunkRelativeUrl 和 getPathFromScript 中得到了正确的应用。我提出了一些改进建议,主要集中在 getRuntimeChunkBasePath 函数中:一个是确保从 globalThis 获取的 publicPath 始终以斜杠结尾,以防止生成错误的 URL;另一个是使警告信息与代码中使用的 globalThis 保持一致。
| if (typeof globalThis !== 'undefined' && typeof (globalThis as any).publicPath === "string") { | ||
| return (globalThis as any).publicPath; | ||
| } |
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.
从 globalThis.publicPath 获取的 publicPath 被直接使用。如果它不以 / 结尾,在与 chunk 路径拼接时可能会导致错误的 URL。例如,如果 publicPath 是 "/assets",而 chunk 路径是 my-chunk.js,结果 URL 将是 "/assetsmy-chunk.js",而不是正确的 "/assets/my-chunk.js"。
为防止此类问题,确保基本路径始终以斜杠结尾非常重要。回退值 "/" 已经遵循了这个模式。
if (typeof globalThis !== 'undefined' && typeof (globalThis as any).publicPath === "string") {
const publicPath = (globalThis as any).publicPath as string;
return publicPath.endsWith('/') ? publicPath : `${publicPath}/`;
}| return (globalThis as any).publicPath; | ||
| } | ||
| console.warn( | ||
| "publicPath is set to 'runtime' but window.publicPath is not defined or not a string, falling back to '/'" |
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.
for issue: utooland/utoo#2244
turbopack 侧的一些运行时代码适配。