mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix retry logic in Fantom when requesting bundles from Metro (#53161)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53161 Changelog: [internal] This fixes a bug in the retry logic in Fantom when requesting bundles from Metro, where we cache the error from a previous attempt and use it to determine we didn't succeed after the attemps. Reviewed By: rshest Differential Revision: D79881488 fbshipit-source-id: 566b2d700db2f9653b9ea9acd577d7eb03770b76
This commit is contained in:
committed by
Facebook GitHub Bot
parent
81fdb9dd93
commit
2f33eece41
+18
-8
@@ -22,8 +22,8 @@ type BundleOptions = {
|
||||
const PROJECT_ROOT = path.resolve(__dirname, '..', '..', '..');
|
||||
|
||||
export async function createBundle(options: BundleOptions): Promise<void> {
|
||||
let bundleResult;
|
||||
let bundleError;
|
||||
let lastBundleResult;
|
||||
let lastBundleError;
|
||||
|
||||
// Retry in case Metro hasn't seen the changes in the filesystem yet.
|
||||
// TODO(T231910841): Remove this when Metro fixes consistency issues when resolving HTTP requests.
|
||||
@@ -33,22 +33,32 @@ export async function createBundle(options: BundleOptions): Promise<void> {
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
lastBundleError = null;
|
||||
lastBundleResult = null;
|
||||
|
||||
try {
|
||||
bundleResult = await fetch(getBundleURL(options));
|
||||
lastBundleResult = await fetch(getBundleURL(options));
|
||||
} catch (e) {
|
||||
bundleError = e;
|
||||
lastBundleError = e;
|
||||
}
|
||||
|
||||
attemps++;
|
||||
} while (attemps < 3 && (bundleError || bundleResult?.status === 404));
|
||||
} while (
|
||||
attemps < 3 &&
|
||||
(lastBundleError || lastBundleResult?.status === 404)
|
||||
);
|
||||
|
||||
if (bundleError || bundleResult?.ok !== true) {
|
||||
if (lastBundleError || lastBundleResult?.ok !== true) {
|
||||
throw new Error(
|
||||
`Failed to request bundle from Metro: ${bundleError?.message ?? (await bundleResult?.text()) ?? ''}`,
|
||||
`Failed to request bundle from Metro: ${lastBundleError?.message ?? (await lastBundleResult?.text()) ?? ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
await fs.promises.writeFile(options.out, await bundleResult.text(), 'utf8');
|
||||
await fs.promises.writeFile(
|
||||
options.out,
|
||||
await lastBundleResult.text(),
|
||||
'utf8',
|
||||
);
|
||||
}
|
||||
|
||||
export async function createSourceMap(options: BundleOptions): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user