Skip to content
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

Fix React 19 deprecation warning when accessing child ref pre-19 way #1416

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

stefcameron
Copy link
Member

@stefcameron stefcameron commented Dec 31, 2024

child.ref is deprecated, and generates a warning in the console in R19 because refs are now first-class props.

Check the React version at runtime and if >=19, access it via the props; otherwise, keep accessing it as before (a property of the child React element object).

Relates to #1343

PR Checklist

Please leave this checklist in your PR.

  • Issue being fixed is referenced.
  • Source changes maintain:
    • Stated browser compatibility.
    • Stated React compatibility.
  • Web APIs introduced have deep browser coverage, including Safari (often very late to adopt new APIs).
  • Unit test coverage added/updated.
  • E2E test coverage added/updated.
  • Prop-types added/updated.
  • Typings added/updated.
  • Changes do not break SSR:
    • Careful to test typeof document/window !== 'undefined' before using it in code that gets executed on load.
  • README updated (API changes, instructions, etc.).
  • Changes to dependencies explained.
  • Changeset added (run npm run changeset locally to add one, and follow the prompts).
    • EXCEPTION: A Changeset is not required if the change does not affect any of the source files that produce the package bundle. For example, demo changes, tooling changes, test updates, or a new dev-only dependency to run tests more efficiently should not have a Changeset since it will not affect package consumers.

Copy link

changeset-bot bot commented Dec 31, 2024

🦋 Changeset detected

Latest commit: cb1778b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
focus-trap-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stefcameron stefcameron mentioned this pull request Dec 31, 2024
@stefcameron stefcameron changed the title [#1343] Fix React 19 deprecation warning when accessing child ref pre-19 way Fix React 19 deprecation warning when accessing child ref pre-19 way Dec 31, 2024
…-19 way

`child.ref` is deprecated, and generates a warning in the console in R19
because refs are now first-class props.

Check the React version at runtime and if `>=19`, access it via the props;
otherwise, keep accessing it as before (a property of the child React element
object).
@stefcameron stefcameron merged commit e766841 into master Dec 31, 2024
4 checks passed
@stefcameron stefcameron deleted the ref-as-prop branch December 31, 2024 16:05
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.

1 participant