Skip to content

Forward port away from deprecated React.ElementRef to React.ComponentRef - #54274

Closed
mikehardy wants to merge 1 commit into
react:mainfrom
mikehardy:ElementRef-becomes-ComponentRef
Closed

Forward port away from deprecated React.ElementRef to React.ComponentRef#54274
mikehardy wants to merge 1 commit into
react:mainfrom
mikehardy:ElementRef-becomes-ComponentRef

Conversation

@mikehardy

Copy link
Copy Markdown
Contributor

Summary:

React v19 deprecated React.ElementRef and recommends using React.ComponentRef

This appears to work just fine, with no other changes other than the type, with the exception of the Codegen phase which makes no allowance for ComponentRef during parsing

I altered the typescript and flow parsers to accept the new ComponentRef as well as the old ElementRef

Changelog:

[INTERNAL][DEPRECATED] - use React.ComponentRef in codegen in place of React.ElementRef

Test Plan:

This is mostly checked in jest tests, I updated the fixtures to send ComponentRef through, and I updated the snapshots to expect a message that indicates either ElementRef or ComponentRef are expected

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 25, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 25, 2025
@mikehardy
mikehardy force-pushed the ElementRef-becomes-ComponentRef branch from 7e9c966 to af65324 Compare October 25, 2025 20:27
@mikehardy

Copy link
Copy Markdown
Contributor Author

There was a linting error in my diff, I fixed that and re-pushed.

The android build error is some deprecation warnings while -Werror is passed, not part of this PR

@cipolleschi cipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @mikehardy for fixing this!

@meta-codesync

meta-codesync Bot commented Oct 27, 2025

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D85556329.

@javache

javache commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

I believe the ComponentRef changes are specific to TypeScript, so no code under flow should be changed. Flow does not have a React.ComponentRef https://flow.org/en/docs/react/types/

@mikehardy

Copy link
Copy Markdown
Contributor Author

@javache oh interesting! I am unfamiliar with flow types and assumed they would be similar, I'll focus this change on typescript when I get a chance / removing the flow bits then and re-push. Thanks for catching that

- Note Typescript has this chance, Flow does not have ComponentRef type,
  so this is typescript-only and Flow did not need a similar change
@mikehardy
mikehardy force-pushed the ElementRef-becomes-ComponentRef branch from af65324 to 4271a9c Compare October 27, 2025 15:10
@mikehardy

Copy link
Copy Markdown
Contributor Author

Okay, @cipolleschi - after Pieter's astute observation that this should be typescript-only since Flow does not have a corresponding change, I have re-pushed this with changes only to the typescript codegen parser + test fixtures + test snapshots. I believe that means you need to reimport?

@meta-codesync meta-codesync Bot closed this in abd3bfb Nov 10, 2025
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Nov 10, 2025
@meta-codesync

meta-codesync Bot commented Nov 10, 2025

Copy link
Copy Markdown

@cipolleschi merged this pull request in abd3bfb.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @mikehardy in abd3bfb

When will my fix make it into a release? | How to file a pick request?

douglowder pushed a commit to react-native-tvos/react-native-tvos that referenced this pull request Nov 15, 2025
…Ref (#54274)

Summary:
React v19 deprecated React.ElementRef and recommends using React.ComponentRef

This appears to work just fine, with no other changes other than the type, with the exception of the Codegen phase which makes no allowance for ComponentRef during parsing

I altered the typescript and flow parsers to accept the new ComponentRef as well as the old ElementRef

- Fixes react/react-native#54272

## Changelog:

[INTERNAL][DEPRECATED] - use React.ComponentRef in codegen in place of React.ElementRef

Pull Request resolved: react/react-native#54274

Test Plan: This is mostly checked in jest tests, I updated the fixtures to send ComponentRef through, and I updated the snapshots to expect a message that indicates either ElementRef or ComponentRef are expected

Reviewed By: javache

Differential Revision: D85556329

Pulled By: cipolleschi

fbshipit-source-id: 0ca4e3929743746da0bde1bfb0e05500db0594f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. sony

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen strictly requires deprecated React.ElementRef vs recommended React.ComponentRef

5 participants