fix(SearchBar): remove stray key field spread into Icon props#4036
Open
tpaulshippy wants to merge 1 commit into
Open
fix(SearchBar): remove stray key field spread into Icon props#4036tpaulshippy wants to merge 1 commit into
tpaulshippy wants to merge 1 commit into
Conversation
All three SearchBar variants (ios/android/default) render the clear
button via renderNode(Icon, clearIcon, { ...defaultClearIcon(theme),
key: 'cancel', onPress }), spreading a plain object containing a
literal "key" field into <Icon {...props} />.
This triggers React's dev-mode warning on every render where the
clear icon shows (i.e. whenever the search input is non-empty):
A props object containing a "key" prop is being spread into JSX
The key field serves no purpose here: Icon isn't part of a list, and
React's JSX runtime strips "key" out of spread props before the
component ever receives it, in both dev and production builds (see
jsxProd in react/cjs/react-jsx-runtime.production.js). Removing it
has no behavioral or visual effect - it only silences the warning.
In consuming apps using Expo Go/dev-client, this warning surfaces as
an in-app error banner pinned to the bottom of the screen, which can
intermittently overlap other bottom-pinned UI and break automated
E2E tests asserting strict tap visibility.
Fixes react-native-elements#4035
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
All three
SearchBarvariants (SearchBar-ios,SearchBar-android,SearchBar-default) render the clear ("X") button via:renderNodespreads this object directly into JSX (<Icon {...defaultProps} {...content} />), and since the object includes a literalkey: 'cancel'field, this triggers React's dev-mode warning on every render where the clear icon is shown (i.e. whenever the search input is non-empty):Why this is safe to remove
The
keyfield serves no purpose here —Iconisn't part of a list being reconciled, and React's JSX runtime stripskeyout of spread props before the component ever receives it, in both dev and production builds. SeejsxProdinreact/cjs/react-jsx-runtime.production.js:So removing this field has no behavioral or visual effect on
SearchBarorIconin any build — it only silences the dev-mode warning.Real-world impact
In a consuming app using Expo Go/dev-client, this warning surfaces as an in-app error banner pinned to the bottom of the screen. That banner can intermittently overlap other bottom-pinned UI (e.g. a fixed nav footer button) and cause automated E2E tests that assert strict tap visibility/hittability (e.g. Detox on iOS) to fail flakily whenever a user has typed something into a
SearchBarearlier in the flow.Closes #4035
Test plan
SearchBar-ios/SearchBar-android/SearchBar-defaultsnapshot tests pass unchanged (no snapshot updates needed —keyisn't part of the serialized output).SearchBarno longer triggers the "props object containing a key prop" warning/banner.