Skip to content

Commit e6d1677

Browse files
authored
feat: guard against augmenting the Metro config twice (#29)
You no longer need to wrap your Metro config with the withRnHarness function because Harness handles this internally. As a result, manually calling withRnHarness should have no effect.
1 parent e821e8d commit e6d1677

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

packages/bundler-metro/src/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const getMetroInstance = async (
5252
port: METRO_PORT,
5353
projectRoot,
5454
});
55-
const config = await withRnHarness(projectMetroConfig)();
55+
const config = await withRnHarness(projectMetroConfig, true)();
5656
const reporter = withReporter(config);
5757

5858
abortSignal.throwIfAborted();

packages/metro/src/withRnHarness.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ const INTERNAL_CALLSITES_REGEX =
1111
/(^|[\\/])(node_modules[/\\]@react-native-harness)([\\/]|$)/;
1212

1313
export const withRnHarness = <T extends MetroConfig>(
14-
config: T | Promise<T>
14+
config: T | Promise<T>,
15+
isInvokedByHarness = false
1516
): (() => Promise<T>) => {
1617
// This is a workaround for a regression in Metro 0.83, when promises are not handled correctly.
1718
return async () => {
19+
// If the function is not invoked by the Harness, return the config as is.
20+
// We'll remove it in the next major version.
21+
if (!isInvokedByHarness) {
22+
return config;
23+
}
24+
1825
const metroConfig = await config;
1926
const { config: harnessConfig } = await getConfig(process.cwd());
2027

0 commit comments

Comments
 (0)