fix(codegen): accept React.ComponentRef in command first-arg#3045
Open
ramonclaudio wants to merge 1 commit into
Open
fix(codegen): accept React.ComponentRef in command first-arg#3045ramonclaudio wants to merge 1 commit into
ramonclaudio wants to merge 1 commit into
Conversation
React 19 renamed `React.ElementRef` to `React.ComponentRef`. The TypeScript commands parser only accepts `ElementRef`, so a NativeCommand whose first arg is typed as `React.ComponentRef` fails codegen with "The first argument of method <name> must be of type React.ElementRef<>". Forward-ports react#54274 (by Mike Hardy): accept both names and update the error message. This unblocks libraries that moved to `ComponentRef`, like react-native-screens 4.26, whose command spec currently breaks the macOS codegen.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@ramonclaudio please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Author
|
@microsoft-github-policy-service agree |
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
React 19 renamed
React.ElementReftoReact.ComponentRef. The TypeScript commands parser inreact-native-codegenonly acceptsElementRefas a command's first argument, so a NativeCommand typed withReact.ComponentReffails codegen:This forward-ports react#54274 (by Mike Hardy), which already made this change on
react-nativemain: accept bothElementRefandComponentRef, and update the error message to match.react-native-macosmain and0.81-stabledon't have it yet.It hits real libraries.
react-native-screens@4.26types itssetToolbarMenuElementOptionscommand's first arg asReact.ComponentRef<>, which builds fine onreact-native(0.86 codegen accepts both) but throws on the macOS target, because the codegen here only knowsElementRef.Changes
Straight forward-port of the upstream commit, three files:
commands.js: acceptReact.ComponentRefalongsideReact.ElementRef, and update the error message.__test_fixtures__/fixtures.jsand the parser snapshot: the matching fixture and snapshot updates from the same upstream commit.ElementRefstill works, so this is additive. Nothing that passed before stops passing.Test plan
react-native-codegenparser tests.If a backport to
0.81-stableis wanted (that's the line consumers like Expo pin today), happy to open one once this lands.