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

Add lint plugin to check for ref access during render #3835

Closed
wants to merge 1 commit into from

Conversation

devongovett
Copy link
Member

Relates to #779.

Reading or writing to refs during render doesn't work in strict mode. This adds a lint plugin to detect this. See facebook/react#24506 for more details. Currently the issues are not fixed, so linter will fail. Someone should go through and fix these.

create(context) {
return {
MemberExpression(member) {
// Look for member expressions that look like refs (i.e. `ref.current`).
Copy link
Member

@snowystinger snowystinger Feb 8, 2023

Choose a reason for hiding this comment

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

I think we're going to need to look for other things as well, such as virtualizer.delegate or virtualizer.anything really https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/virtualizer/src/useVirtualizerState.ts#L55

we'll also probably want to check if current is being written to or read from inside a useMemo since that's equivalent to render time? https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/useCollection.ts#L25

Copy link
Member

Choose a reason for hiding this comment

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

probably things like our weak maps hook contexts as well
which are hard because we can't just put the writes and reads into useLayoutEffect since the child ones would run before the parent... so they'd always run on stale data
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/calendar/src/useCalendarBase.ts#L66
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/calendar/src/useCalendarGrid.ts#L125

devongovett added a commit that referenced this pull request May 22, 2023
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