ScriptManager caches the rejected promise when a resolver throws, so loadScript/prefetchScript never retry
維護者通常 2 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- react-native, typescript, webpack
- 領域
- tooling
研究方向
Read the loadScript and prefetchScript implementations in ScriptManager and the linked ScriptManager.test.ts reproduction. Check how each method handles a rejected resolveScript call and how its cached promise is cleaned up. Done when the resolver is called again on a retry after a resolver failure, and both reproduction tests pass.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
If a script resolver throws, ScriptManager keeps the rejected promise in scriptsPromises. Every later loadScript / prefetchScript call for the same script returns that same error and never calls the resolvers again. The only way out is to restart the app.
In loadScript and prefetchScript, resolveScript is awaited before the try / finally that removes the entry from scriptsPromises:
const loadProcess = async () => {
let script = await this.resolveScript(/* ... */); // a throw here skips the finally below
try {
// ...
} catch (error) {
// ...
} finally {
// should delete script promise even script failed
delete this.scriptsPromises[uniqueId];
}
};
this.scriptsPromises[uniqueId] = loadProcess();
So the "delete even if it failed" path only runs for loading errors, not for resolving errors. The same pattern is in prefetchScript. It also affects loadScript after a failed prefetchScript, because loadScript awaits the cached prefetch promise and rethrows its error.
Expected: after a resolver error (e.g. the device was offline while the resolver fetched the script URL), the next loadScript call runs the resolvers again, the same way it already retries after a failed native load.
Actual: the next loadScript calls reject right away with the first error, even after the network is back. In our app a user who opened a mini app while offline could not open it again until they killed and reopened the app. A retry button on an error boundary or React.lazy remount did not help.
System Info
React Native 0.79.7 (New Architecture, Hermes)
@callstack/repack 5.2.5, bundler webpack 5, Module Federation v1
iOS and Android, release builds
Re.Pack Version
5.2.5. The code is unchanged in 5.4.2 and on main (32c32c0).
Reproduction
https://github.com/linhh-phv/repack/blob/fix/script-manager-retry-after-resolve-failure/packages/repack/src/modules/ScriptManager/__tests__/ScriptManager.test.ts. The two tests should retry loadScript after resolver failure and should retry prefetchScript after resolver failure fail on main and pass with the fix.
Steps to reproduce
-
Add a resolver that rejects once, then resolves:
const resolver = jest .fn() .mockRejectedValueOnce(new Error('Network request failed')) .mockImplementation(async (scriptId) => ({ url: Script.getRemoteURL(scriptId) })); ScriptManager.shared.addResolver(resolver); -
await ScriptManager.shared.loadScript('miniApp')rejects withNetwork request failed, as expected. -
Call
await ScriptManager.shared.loadScript('miniApp')again: it rejects with the same error andresolverwas called only once.
In an app: make the resolver depend on the network (for example, fetch the version or URL of a remote), open a federated remote while offline, turn the network back on, then try to open it again.
I have a fix ready and will open a PR: delete the cached promise when resolveScript throws, then rethrow.
- 主要語言
- TypeScript
- 星號
- 1.9k
- 分支
- 177
- 平均合併
- 2 天 10 小時
- 30 天內合併 PR
- 23
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
callstack/repack 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
callstack/repack#1515 · 2 則留言 ·
維護者通常 2 天內回覆
-
remove absolute file paths embedded in sourcemaps generated by `SourceMapPlugin`可能已有人在做 @JaydeepAgravat 於 1 天前認領。 未關閉status:new type:feature
難度 3/5 1-2 天 新手友好度 50/100
callstack/repack#1518 · 1 則留言 ·
維護者通常 2 天內回覆
-
Inlined assets with fractional scales resolve to the wrong variant可能已有人在做 @RaphaelFakhri 於 17 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 25/100
維護者通常 2 天內回覆
-
json as string in JS bundle可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 5/5 一週以上 新手友好度 35/100
callstack/repack#1461 · 1 則留言 ·
維護者通常 2 天內回覆
-
area:repack type:feature
難度 5/5 一週以上 新手友好度 42/100
callstack/repack#1423 · 1 則留言 ·
維護者通常 2 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
transitmatters/shutdown-tracker#155 ·
維護者通常 2 天內回覆
-
bug triaged
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
"Claude Code request is missing its initial user message" when the prompt starts with an image path未關閉
難度 2/5 1-3 小時 新手友好度 84/100
earendil-works/pi-claude-code#31 ·
維護者通常 8 天內回覆
-
bug pending triage
難度 1/5 1 小時以內 新手友好度 92/100
privatenumber/cleye#48 ·