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

feat: Support Ref Cleanup #7758

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chirokas
Copy link
Contributor

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@snowystinger
Copy link
Member

Thanks for the interest, it appears this is a React 19 only feature https://react.dev/blog/2024/12/05/react-19#cleanup-functions-for-refs

I noticed that all the tests, React 16, 17 and 18, pass. How much of the work here makes it work with previous versions? I still get a console warning if I try to use it, so I don't think it's a use case we should support. We can turn off the test for the other versions of React.

@chirokas
Copy link
Contributor Author

chirokas commented Feb 12, 2025

I still get a console warning if I try to use it

// React 16, 17 and 18

<input ref={mergeRefs(onRefChangeWithCleanup)} />
// Warning: Unexpected return value from a callback ref
// https://github.com/facebook/react/pull/22313

We don't handle ref cleanups internally, so this still happens in React < 19 when a user's ref callback returns a value.

However, it works well

<input ref={useObjectRef(mergeRefs(onRefChangeWithCleanup))} />

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Initially looks good, I've added some preliminary mergeRef tests in case we think of others edge cases we should try

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