feat: enhance error handling for script loading and execution#4538
feat: enhance error handling for script loading and execution#4538
Conversation
🦋 Changeset detectedLatest commit: 6c76d23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 45 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
9258f58 to
94d6139
Compare
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/data-prefetch
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9258f5815c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }).then( | ||
| () => { | ||
| // loadScript resolved: script was fetched, executed without throwing, and | ||
| // did not trigger a ScriptExecutionError listener. Now verify the global was registered. | ||
| return handleRemoteEntryLoaded(name, globalName, entry); |
There was a problem hiding this comment.
Preserve RUNTIME_008 mapping for script timeouts
Switching to .then(onFulfilled, onRejected) means any error thrown in handleRemoteEntryLoaded now bypasses the RUNTIME_008 wrapper, but loadScript timeouts still resolve (the timeout path in packages/sdk/src/dom.ts calls the success callback), so a timed-out remote now falls into this fulfillment branch and is rethrown as RUNTIME_001 instead of RUNTIME_008. In timeout conditions this breaks retry-plugin triggering (loadEntryError only runs on RUNTIME_008) and changes user-facing diagnostics from load failure to missing global.
Useful? React with 👍 / 👎.
Bundle Size Report15 package(s) changed, 25 unchanged. Package dist + ESM entry
Bundle targets
Consumer scenarios
Total dist (raw): 6.30 MB (+5.5 kB (+0.1%)) Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as |
Description
feat: improve script load error discrimination and retry guard
Background
Previously, all failures in loadEntryScript — network 404, CORS, timeout, and IIFE runtime exceptions — were reported uniformly as
RUNTIME-008 with no distinguishing detail. Additionally, when a script's IIFE threw during execution, script.onload still fired (standard
browser behavior), silently discarding the original exception.
Changes
packages/sdk/src/dom.ts
matching evt.filename against the script URL
packages/runtime-core/src/utils/load.ts
handleRemoteEntryLoaded are not mistakenly caught and re-reported as RUNTIME-008
not emitted and the retry-plugin is never triggered
Tests
and listener cleanup
error, global not registered, and successful load
Docs
subtypes (ScriptNetworkError / ScriptExecutionError), their causes, and targeted troubleshooting steps