-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[TrapFocus] Guard against dropped memo cache #20848
Conversation
Details of bundle changes.Comparing: 7d7e756...5d0c2a5 Details of page changes
|
Co-Authored-By: Josh Wooding <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to benchmark how a couple of alternatives handle the problem. I have found:
- Call during the constructor: https://github.com/davidtheclark/focus-trap-react/blob/e67d26c5ff512228007bd6eb55aea9841eb7e09d/src/focus-trap-react.js#L10
- Call during componentWillMount https://github.com/theKashey/react-focus-lock/blob/7a6c0c916a7f5c0a040bece84a8dea4e5f999b6d/src/Trap.js#L130
- Call during componentWillReceiveProps https://github.com/microsoft/fluentui/blob/4039ef722c1c3ee5bf14eed0a49477eaf773cd08/packages/office-ui-fabric-react/src/components/FocusTrapZone/FocusTrapZone.tsx#L40
- Call during the effect: https://github.com/zendeskgarden/react-containers/blob/be96fbd372bbde9d2cce30461b5027c78cbac221/packages/focusjail/src/useFocusJail.ts#L119.
Any idea how we could solve this?
What are you trying to solve? |
I was wondering about the concurrent mode issue you have raised and added as a comment. |
Which is not an issue for the first 3 links. They obviously are meant to not work in concurrent mode. During a passive effect is too late for I think I made it clear that it's unclear whether this is actually an issue in concurrent mode considering how the committed effects relate to the |
It's still potentially unsafe for concurrent mode but at least it's now safe against useMemo dropping the cache because we create our own cache via
useRef
.**Also adds a warning for a potential memory leak since
nodeToRestore.current
could be unmounted while the modal is open. Though this is pretty unlikely to be an issue since you usually don't have many open modals.