ScriptManager caches the rejected promise when a resolver throws, so loadScript/prefetchScript never retry
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- react-native, typescript, webpack
- Bereich
- tooling
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1.9k
- Forks
- 177
- Ø Merge
- 2 T. 10 Std.
- Gemergte PRs (30 T.)
- 23
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus callstack/repack
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
callstack/repack#1515 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
status:new type:feature
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 50/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Inlined assets with fractional scales resolve to the wrong variantEvtl. vergeben @RaphaelFakhri hat das vor 15 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 2 Tagen
-
json as string in JS bundleEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
callstack/repack#1461 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
area:repack type:feature
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 42/100
callstack/repack#1423 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in callstack/repack
Ähnliche Issues
-
bug module:nodes tests
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
rocketride-org/rocketride-server#3020 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
area: dashboard area: tests good first issue size: XS tests
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
Read canvas commentsOffenenhancement needs-community-review
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
shaharia-lab/slackcli#501 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] Pod detail shows CPU usage ten times too high, and throws on decimal memory suffixesEvtl. vergeben @RaphaelFakhri hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 11 Tagen
-
`package.json`: build tools listed as runtime dependencies, exact pins causing duplicate installsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
themesberg/flowbite-vue#471 ·