Skip to content

Conversation

snowystinger
Copy link
Member

@snowystinger snowystinger commented Oct 10, 2025

Closes

Updates to the latest eslint plugin for react to use the compiler. The main transforms I applied are detailed in this issue Confusion with useEffectEvent lint rules

Note, I had to use useLayoutEffect to get the synchronous behaviour in React 16 and 17 so that events fired back to back would still have the effect run between them. (for example,
This could also be accomplished with flushSync, but then that takes us out of concurrent mode.

This PR mostly focuses on react-hooks/rules-of-hooks

✅ 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:

@rspbot
Copy link

rspbot commented Oct 10, 2025

@devongovett
Copy link
Member

The linter is probably correct about the errors with our useEffectEvent. We should try to solve those instead of renaming the hook.

@snowystinger
Copy link
Member Author

Darn, just a gut feeling? Or is there something in particular you're worried about? Trying to understand the rules better

@devongovett
Copy link
Member

Child effects run before parents so the function won't necessarily be bound yet if you pass one down

@snowystinger
Copy link
Member Author

Child effects run before parents so the function won't necessarily be bound yet if you pass one down

Ok, so nothing beyond what I noted in the description, which we don't currently violate from what I saw. Will explore some fixes this week.

@rspbot
Copy link

rspbot commented Oct 13, 2025

@rspbot
Copy link

rspbot commented Oct 15, 2025

@rspbot
Copy link

rspbot commented Oct 15, 2025

removeGlobalListener(window, 'pointerup', onPointerUp, false);
removeGlobalListener(window, 'pointercancel', onPointerUp, false);
};
} else if (pointerDown === 'mouse' && process.env.NODE_ENV === 'test') {
Copy link
Member Author

Choose a reason for hiding this comment

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

technically these can only happen during test environment, but i've added here so that the dead code remover knows to get rid of it

@rspbot
Copy link

rspbot commented Oct 17, 2025

@rspbot
Copy link

rspbot commented Oct 17, 2025

## API Changes

@react-aria/utils

/@react-aria/utils:useUpdateEffect

 useUpdateEffect {
-  effect: EffectCallback
+  cb: EffectCallback
   dependencies: Array<any>
   returnVal: undefined
 }

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

I'll have to come back to the usePress change (I think it is mainly just code moving around), but my comment on the useAutocomplete change encompasses my main thoughts about the change, primarily a slight concern around move away from using useEffectEvent since they are scoped to useEffectEvents/useEffects within the same component by the linter, but that means things that used to be returned from various hooks are now reactive again. Maybe a nothing burger

}, []);

let updateActiveDescendant = useEffectEvent((e: Event) => {
let updateActiveDescendant = useCallback((e: Event) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure I understand this update here. This would mean the callbackRef below now will become reactive to changes in state/shouldVirtualFocus and thus remove and re-add the event listener every time the user types/moves virtual focus. However, if we use useEffectEvent we only need to attach the listener once and we will still get up to date values in this call.

I guess this is because of reactjs/react.dev#8075 (comment) and on where this may become a potential pitfall?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is another option, I could set a state as a result of the callback ref when the component mounts. Then in an effect I could attach the listener instead. Then I can use this an an effect event again. I was opting for less renders, but it does mean detach and reattach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants