From b14b34b232b4873137ea3f3c7a90f86b9013885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 8 Oct 2021 07:37:41 -0700 Subject: [PATCH] Make runtime initialization from React renderers a no-op 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 https://github.com/facebook/react-native/pull/30188#issuecomment-929352747). 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 --- .../ReactPrivate/ReactNativePrivateInitializeCore.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js b/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js index e34e6271f2f7fe..975e173537978d 100644 --- a/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js +++ b/Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js @@ -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).