Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metro-config] add InitializeCore in getModulesRunBeforeMainModule #38207

Closed
wants to merge 2 commits into from

Conversation

Kudo
Copy link
Contributor

@Kudo Kudo commented Jul 6, 2023

Summary:

the IntializeCore is critical to react-native for setup polyfills. without this, we would have some erros like undefined global.performance. since the effort is now proposing @react-native/metro-config as universal metro-config, it is better to have the IntializeCore in it.

we ran into issues when using expo-cli in bare react-native projects. it happens when using the default metro config and starting metro server without the react-native-community-cli.

Why the issue does not happen on yarn react-native start?

when using yarn react-native start, the react-native-community-cli will merge its internal metro-config with the InitializeCore (#1, #2). that's why the issue doesn't happen on react-native-community-cli.

Changelog:

[GENERAL][FIXED] - global.performance in undefined when starting metro from Expo CLI

Test Plan:

$ npx react-native init RN072 --version 0.72
$ cd RN072
$ yarn add expo
$ npx expo run:ios
# then it hits the exception because the global.performance is undefined.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. p: Expo Partner: Expo Partner labels Jul 6, 2023
@analysis-bot
Copy link

analysis-bot commented Jul 6, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,061,546 +61,568
android hermes armeabi-v7a 8,310,881 +56,799
android hermes x86 9,577,764 +68,626
android hermes x86_64 9,420,185 +65,297
android jsc arm64-v8a 9,613,324 +2
android jsc armeabi-v7a 8,739,956 +0
android jsc x86 9,700,287 +1
android jsc x86_64 9,946,839 +0

Base commit: 62e9fae
Branch: main

@facebook-github-bot
Copy link
Contributor

@huntie has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Member

@huntie huntie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change upstream @Kudo! Small nit then we'll ship this 👍🏻

packages/metro-config/index.js Show resolved Hide resolved
Co-authored-by: Alex Hunt <hello@alexhunt.io>
@facebook-github-bot
Copy link
Contributor

@huntie has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@github-actions
Copy link

github-actions bot commented Jul 7, 2023

This pull request was successfully merged by @Kudo in 0ccbd65.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Jul 7, 2023
@Kudo Kudo deleted the @kudo/metro-config-init-core branch July 7, 2023 14:58
kelset pushed a commit that referenced this pull request Jul 10, 2023
Summary:
the `IntializeCore` is critical to react-native for setup polyfills. without this, we would have some erros like undefined `global.performance`. since the effort is now proposing `react-native/metro-config` as universal metro-config, it is better to have the `IntializeCore` in it.

we ran into issues when using expo-cli in bare react-native projects. it happens when using [the default metro config](https://github.com/facebook/react-native/blob/5f84d7338f42fe9b1d5bf2a9b1c8321b59551f15/packages/react-native/template/metro.config.js) and starting metro server without the react-native-community-cli.

### Why the issue does not happen on `yarn react-native start`?

when using `yarn react-native start`, the react-native-community-cli will merge its internal metro-config with the `InitializeCore` ([https://github.com/facebook/react-native/issues/1](https://github.com/react-native-community/cli/blob/5d8a8478cd104adf4a4dd34c09c2e256325ae61d/packages/cli-plugin-metro/src/commands/start/runServer.ts#L56), [https://github.com/facebook/react-native/issues/2](https://github.com/react-native-community/cli/blob/e8e7402512da8c3fbbc58a195284ef0008c7491f/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts#L51-L61)). that's why the issue doesn't happen on react-native-community-cli.

## Changelog:

[GENERAL][FIXED] - `global.performance` in undefined when starting metro from Expo CLI

Pull Request resolved: #38207

Test Plan:
```sh
$ npx react-native init RN072 --version 0.72
$ cd RN072
$ yarn add expo
$ npx expo run:ios
# then it hits the exception because the global.performance is undefined.
```

Reviewed By: rshest

Differential Revision: D47257439

Pulled By: huntie

fbshipit-source-id: ae294e684047e503d674f0c72563b56d1803ba36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Merged This PR has been merged. p: Expo Partner: Expo Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants