From 4064e8dab1b41fd536a5c5d3296dac3749f5af31 Mon Sep 17 00:00:00 2001 From: James Ide Date: Sat, 28 Nov 2026 02:50:29 -0800 Subject: [PATCH] Skip static view config verification without native view configs A bridgeless host that sets `setRuntimeConfigProvider(() => ({native: false, verify: true}))` and has no legacy view config interop binding logs a console.error the first time each native component is used: [ReactNative Architecture][JS] 'getViewManagerConfig('RCTView')' is not available in the new React Native architecture. ... Verification compares a component's static view config with its native one. In bridgeless mode, `UIManager.getViewManagerConfig` reads native view configs from `global.RN$LegacyInterop_UIManager_getConstants`. Native installs that binding only when `useNativeViewConfigsInBridgelessMode` is on, and an iOS build with `RCT_REMOVE_LEGACY_COMPONENT_INTEROP` never installs it. Without the binding, the call logs the error and returns null for every component, and verification then does nothing. The flag is off in `ReactNativeFeatureFlagsDefaults`. The stock entry points turn it on (`RCTReactNativeFactory` on iOS, the new architecture defaults on Android), so RNTester as shipped is affected only when it is built with `RCT_REMOVE_LEGACY_COMPONENT_INTEROP`. `NativeComponentRegistry.get` now skips verification when the binding is absent, without asking for the native view config. `getWithFallback_DEPRECATED` reaches the same error another way. With no runtime config provider set, it checks that a component exists with `getViewManagerConfig(name) != null`, which logs the error and returns the fallback for a component that exists. It now calls `hasViewManagerConfig(name)`, which is the same null check on the old architecture and asks the native component registry in bridgeless mode. Co-Authored-By: Claude Opus 5.5 --- .../NativeComponentRegistry.js | 11 +- .../__tests__/NativeComponentRegistry-test.js | 115 ++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js diff --git a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js index deedfb009041..54393bdfda75 100644 --- a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js +++ b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js @@ -76,6 +76,15 @@ export function get( ); if (verify) { + // In bridgeless mode, native view configs come from the legacy view + // config interop binding. Without it, asking for one logs an error. + if ( + global.RN$Bridgeless === true && + global.RN$LegacyInterop_UIManager_getConstants == null + ) { + return viewConfig; + } + const nativeViewConfig = native ? viewConfig : getNativeComponentAttributes(name); @@ -149,7 +158,7 @@ export function getWithFallback_DEPRECATED( function hasNativeViewConfig(name: string): boolean { invariant(getRuntimeConfig == null, 'Unexpected invocation!'); - return UIManager.getViewManagerConfig(name) != null; + return UIManager.hasViewManagerConfig(name); } /** diff --git a/packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js b/packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js new file mode 100644 index 000000000000..1ff0fb0eb6c4 --- /dev/null +++ b/packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js @@ -0,0 +1,115 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +import type {PartialViewConfig} from '../../Renderer/shims/ReactNativeTypes'; + +// The Jest preset replaces this module with a mock. +jest.unmock('../NativeComponentRegistry'); + +const NAME = 'RCTTestComponent'; + +const PARTIAL_VIEW_CONFIG: PartialViewConfig = { + uiViewClassName: NAME, + validAttributes: {}, +}; + +const originalBridgeless = global.RN$Bridgeless; +const originalGetConstants = global.RN$LegacyInterop_UIManager_getConstants; + +beforeEach(() => { + jest.resetModules(); +}); + +afterEach(() => { + // $FlowExpectedError[cannot-write] + global.RN$Bridgeless = originalBridgeless; + // $FlowExpectedError[cannot-write] + global.RN$LegacyInterop_UIManager_getConstants = originalGetConstants; +}); + +describe('get with verify', () => { + function getNativeViewConfigRequests({ + bridgeless, + interop, + }: { + bridgeless: boolean, + interop: boolean, + }): ReadonlyArray { + // $FlowExpectedError[cannot-write] + global.RN$Bridgeless = bridgeless; + // $FlowExpectedError[cannot-write] + global.RN$LegacyInterop_UIManager_getConstants = interop + ? () => ({}) + : undefined; + const getNativeComponentAttributes = jest.fn((name: string) => null); + jest.doMock( + '../../ReactNative/getNativeComponentAttributes', + () => getNativeComponentAttributes, + ); + + const NativeComponentRegistry = require('../NativeComponentRegistry'); + NativeComponentRegistry.setRuntimeConfigProvider(() => ({ + native: false, + verify: true, + })); + NativeComponentRegistry.get<{...}>(NAME, () => PARTIAL_VIEW_CONFIG); + // `get` registers a lazy view config. Reading it runs the verification. + require('../../Renderer/shims/ReactNativeViewConfigRegistry').get(NAME); + + return getNativeComponentAttributes.mock.calls.map(([name]) => name); + } + + test('does not request a native view config in bridgeless mode without the interop binding', () => { + expect( + getNativeViewConfigRequests({ + bridgeless: true, + interop: false, + }), + ).toEqual([]); + }); + + test('requests the native view config in bridgeless mode with the interop binding', () => { + expect( + getNativeViewConfigRequests({ + bridgeless: true, + interop: true, + }), + ).toEqual([NAME]); + }); + + test('requests the native view config outside bridgeless mode', () => { + expect( + getNativeViewConfigRequests({ + bridgeless: false, + interop: false, + }), + ).toEqual([NAME]); + }); +}); + +describe('getWithFallback_DEPRECATED without a runtime config provider', () => { + test('finds a component without requesting its view config', () => { + const getViewManagerConfig = jest.fn((name: string) => null); + jest.doMock('../../ReactNative/UIManager', () => ({ + getViewManagerConfig, + hasViewManagerConfig: (name: string) => name === NAME, + })); + + const NativeComponentRegistry = require('../NativeComponentRegistry'); + + expect( + NativeComponentRegistry.getWithFallback_DEPRECATED<{...}>( + NAME, + () => PARTIAL_VIEW_CONFIG, + ), + ).toBe(NAME); + expect(getViewManagerConfig).not.toHaveBeenCalled(); + }); +});