Skip to content

fix: detect bare Switch host component name - #1932

Open
christophpurrer wants to merge 1 commit into
callstack:mainfrom
christophpurrer:hostnameswitch
Open

fix: detect bare Switch host component name#1932
christophpurrer wants to merge 1 commit into
callstack:mainfrom
christophpurrer:hostnameswitch

Conversation

@christophpurrer

Copy link
Copy Markdown

Summary

The iOS native component spec codegens under the name Switch, but HOST_SWITCH_NAMES only listed the legacy RCTSwitch name, so isHostSwitch returned false for elements with that host name.

Add Switch alongside RCTSwitch, mirroring how HOST_TEXT_NAMES already accepts both Text and RCTText.

See: react/react-native#58323

Test plan

Added detects raw Switch component to src/tests/host-component-names.test.tsx. It fails on main and passes with this change. Full suite, typecheck, lint and format:check all pass.

The iOS native component spec codegens under the name `Switch`, but
`HOST_SWITCH_NAMES` only listed the legacy `RCTSwitch` name, so
`isHostSwitch` returned `false` for elements with that host name.

Add `Switch` alongside `RCTSwitch`, mirroring how `HOST_TEXT_NAMES`
already accepts both `Text` and `RCTText`.

See: react/react-native#58323
// The iOS native component spec codegens under the name `Switch`, so the bare
// name has to be recognised alongside the legacy `RCTSwitch` one.
test('detects raw Switch component', async () => {
await render(React.createElement('Switch', { testID: 'switch' }));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does render? RCTSwitch? In real code how do you access that Switch with out RCT prefix?

@mdjastrzebski

Copy link
Copy Markdown
Member

Does it affect any stable RN version?

We have a nightly job running for every RN version, incl. latest, next and canary, that checks the following test:

test('detects host Switch component', async () => {
  await render(<Switch />);
  expect(isHostSwitch(screen.root)).toBe(true);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants