Repository navigation
Skip static view config verification without native view configs #60361
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
Merged
meta-codesync
merged 1 commit into
react:main
from
expo:@ide/skip-unavailable-view-config-verification
Dec 4, 2026
+180
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
packages/react-native/Libraries/NativeComponent/__tests__/NativeComponentRegistry-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| /** | ||
| * 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 SECOND_NAME = 'RCTSecondTestComponent'; | ||
|
|
||
| const PARTIAL_VIEW_CONFIG: PartialViewConfig = { | ||
| uiViewClassName: NAME, | ||
| validAttributes: {}, | ||
| }; | ||
|
|
||
| const SECOND_PARTIAL_VIEW_CONFIG: PartialViewConfig = { | ||
| uiViewClassName: SECOND_NAME, | ||
| validAttributes: {}, | ||
| }; | ||
|
|
||
| const originalBridgeless = global.RN$Bridgeless; | ||
| const originalGetConstants = global.RN$LegacyInterop_UIManager_getConstants; | ||
| const originalDev = global.__DEV__; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetModules(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| // $FlowExpectedError[cannot-write] | ||
| global.RN$Bridgeless = originalBridgeless; | ||
| // $FlowExpectedError[cannot-write] | ||
| global.RN$LegacyInterop_UIManager_getConstants = originalGetConstants; | ||
| // $FlowExpectedError[cannot-write] | ||
| global.__DEV__ = originalDev; | ||
| }); | ||
|
|
||
| describe('get with verify', () => { | ||
| function getNativeViewConfigRequests({ | ||
| bridgeless, | ||
| dev = true, | ||
| interop, | ||
| names = [NAME], | ||
| }: { | ||
| bridgeless: boolean, | ||
| dev?: boolean, | ||
| interop: boolean, | ||
| names?: ReadonlyArray<string>, | ||
| }): ReadonlyArray<string> { | ||
| // $FlowExpectedError[cannot-write] | ||
| global.__DEV__ = dev; | ||
| // $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, | ||
| })); | ||
| const ViewConfigRegistry = require('../../Renderer/shims/ReactNativeViewConfigRegistry'); | ||
| for (const componentName of names) { | ||
| const config = | ||
| componentName === SECOND_NAME | ||
| ? SECOND_PARTIAL_VIEW_CONFIG | ||
| : PARTIAL_VIEW_CONFIG; | ||
| NativeComponentRegistry.get<{...}>(componentName, () => config); | ||
| // Reading the registered lazy view config runs verification | ||
| ViewConfigRegistry.get(componentName); | ||
| } | ||
|
|
||
| return getNativeComponentAttributes.mock.calls.map(([name]) => name); | ||
| } | ||
|
|
||
| test('skips verification and warns once in development without the interop binding in bridgeless mode', () => { | ||
| const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
|
||
| expect( | ||
| getNativeViewConfigRequests({ | ||
| bridgeless: true, | ||
| interop: false, | ||
| names: [NAME, SECOND_NAME], | ||
| }), | ||
| ).toEqual([]); | ||
| expect(warnSpy).toHaveBeenCalledTimes(1); | ||
| expect(warnSpy).toHaveBeenCalledWith( | ||
| expect.stringContaining('Skipping static view config verification'), | ||
| ); | ||
| }); | ||
|
|
||
| test('does not warn outside development without the interop binding in bridgeless mode', () => { | ||
| const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
|
||
| expect( | ||
| getNativeViewConfigRequests({ | ||
| bridgeless: true, | ||
| dev: false, | ||
| interop: false, | ||
| }), | ||
| ).toEqual([]); | ||
| expect(warnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('requests the native view config in bridgeless mode with the interop binding', () => { | ||
| const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
|
||
| expect( | ||
| getNativeViewConfigRequests({ | ||
| bridgeless: true, | ||
| interop: true, | ||
| }), | ||
| ).toEqual([NAME]); | ||
| expect(warnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('requests the native view config outside bridgeless mode', () => { | ||
| const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
|
|
||
| expect( | ||
| getNativeViewConfigRequests({ | ||
| bridgeless: false, | ||
| interop: false, | ||
| }), | ||
| ).toEqual([NAME]); | ||
| expect(warnSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| 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(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a
warnOncein development?verifywas enabled but legacy interop is disabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added a dev-only
warnOncein f416ed4 whenverifyis enabled without the legacy view config interop binding, along with unit tests covering dev and non-dev behavior.