Skip to content

FocusScope broken in React 18 StrictMode #3458

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

Closed
RubenStoesser opened this issue Aug 29, 2022 · 1 comment
Closed

FocusScope broken in React 18 StrictMode #3458

RubenStoesser opened this issue Aug 29, 2022 · 1 comment

Comments

@RubenStoesser
Copy link

🐛 Bug Report

The last update (v3.8.0) to @react-aria/focus has introduced code that breaks FocusScope when running in React 18 StrictMode.

Rendering a <FocusScope throws this error:

Cannot set properties of undefined (setting 'nodeToRestore')

The issue does not occur when StrictMode is not enabled or v3.7.0 of @react-aria/focus is used.

🤔 Expected Behavior

FocusScope should not throw an error when rendering.

😯 Current Behavior

Whenever a FocusScope is rendered in StrictMode an error is thrown:

Cannot set properties of undefined (setting 'nodeToRestore')

The error seems to be thrown when trying to assign focusScopeTree.getTreeNode(scopeRef).nodeToRestore in this useLayoutEffect:

💻 Code Sample

Example Code Sandbox using the example code from react-aria docs:

https://codesandbox.io/s/react-spectrum-template-forked-88lk5n?file=/src/App.js

To reproduce just click on the "open" button.

Note that when <StrictMode> is removed in the index.js file the error does not occur.
When the version of @react-aria/focus is changed to 3.7.0 the error also does not occur.

🌍 Your Environment

Software Version(s)
@react-aria/focus 3.8.0
Browser Chrome 104.0.5112.101
Operating System MacOS 12.5.1
@RubenStoesser RubenStoesser changed the title FocusScope breaks in React.StrictMode FocusScope broken in React.StrictMode Aug 29, 2022
@RubenStoesser RubenStoesser changed the title FocusScope broken in React.StrictMode FocusScope broken in React 18 StrictMode Aug 29, 2022
@reidbarber
Copy link
Member

Thanks for finding! We have an umbrella issue for strict mode issues at #779, so I'll close this in favor of that.

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

No branches or pull requests

2 participants