Skip to content

Commit

Permalink
Make runtime initialization from React renderers a no-op
Browse files Browse the repository at this point in the history
Summary:
This module is imported by all flavors of the React Native renderers (dev/prod, Fabric/Paper, etc.), which itself imports `InitializeCore`. This is effectively a no-op in most React Native apps because Metro adds it as a module to execute before the entrypoint of the bundle.

This import would be harmless if all React Native apps included all polyfills and globals, but some of them don't want to include everything and instead of importing `InitializeCore` they import individual setup functions (like `setupXhr`). Having this automatic import in the renderer defeats that purpose (most importantly for app size), so we should remove it.

The main motivation for this change is to increase the number (and spec-compliance) of Web APIs that are supported out of the box without adding that cost to apps that choose not to use some of them (see #30188 (comment)).

Changelog: [General][Removed] Breaking: Removed initialization of React Native polyfills and global variables from React renderers.

Note: this will only be a breaking change for apps not using the React Native CLI, Expo nor have a Metro configuration that executes `InitializeCore` automatically before the bundle EntryPoint.

Reviewed By: yungsters

Differential Revision: D31472153

fbshipit-source-id: 92eb113c83f77dbe414869fbce152a22f3617dcb
  • Loading branch information
rubennorte authored and facebook-github-bot committed Oct 8, 2021
1 parent a101fc7 commit b14b34b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
* @flow strict-local
*/

import '../Core/InitializeCore';
// TODO: Remove this module when the import is removed from the React renderers.

// This module is used by React to initialize the React Native runtime,
// but it is now a no-op.

// This is redundant because all React Native apps are already executing
// `InitializeCore` before the entrypoint of the JS bundle
// (see https://github.com/react-native-community/cli/blob/e1da64317a1178c2b262d82c2f14210cdfa3ebe1/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts#L93)
// and importing it unconditionally from React only prevents users from
// customizing what they want to include in their apps (re: app size).

0 comments on commit b14b34b

Please sign in to comment.