feat(turbopack): add loadScript method for script external#114
feat(turbopack): add loadScript method for script external#114fireairforce merged 1 commit intoutoofrom
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 capability to manage external dependencies by introducing a dedicated mechanism for loading scripts from external URLs. This feature is essential for integrating third-party libraries or components hosted on CDNs, ensuring that the runtime can dynamically fetch and execute these scripts while providing improved reliability and error reporting for such operations. Highlights
Changelog
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 introduces a new loadScript method to handle external scripts, which is a great addition. The implementation includes a new runtime function in TypeScript for loading scripts in the browser and updates the Rust code to generate more robust JavaScript for handling these externals. The new logic correctly uses globalThis and provides better error handling.
I've left one suggestion to improve the error handling in the loadScript function to allow for retries on failure and to clean up the DOM.
| script.onerror = () => | ||
| reject(new Error(`Failed to load script: ${scriptUrl}`)) |
There was a problem hiding this comment.
When a script fails to load, the rejected promise is cached. This prevents any subsequent attempts to load the script from retrying, as they will immediately receive the cached rejected promise. It's better to remove the failed script's promise from the cache to allow for retries (e.g., in case of a transient network error).
Additionally, the failed <script> tag remains in the document's <head>, which is unnecessary. It should be removed on error.
script.onerror = () => {
loadedScripts.delete(scriptUrl)
script.remove()
reject(new Error(`Failed to load script: ${scriptUrl}`))
}
No description provided.