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

[core] Remove RootRef usage #15347

Merged
merged 7 commits into from
Apr 21, 2019

Conversation

joshwooding
Copy link
Member

@joshwooding joshwooding commented Apr 14, 2019

After #15291, is merged TrapFocus is the only usage of RootRef.
This would be a breaking change because TrapFocus can only accept components that forward refs which affects everything that uses a Modal.

Fade and Grow needed to forward refs as they're used inside TrapFocus. Maybe we should do the same for the other Transitions?

pages/api/fade.md Outdated Show resolved Hide resolved
@mui-pr-bot
Copy link

mui-pr-bot commented Apr 14, 2019

Details of bundle changes.

Comparing: 522c8f7...07ef2e9

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.02% +0.02% 🔺 312,616 312,565 84,445 84,464
@material-ui/core/Paper -0.00% -0.02% 67,279 67,277 19,968 19,964
@material-ui/core/Paper.esm 0.00% 0.00% 60,640 60,640 18,884 18,884
@material-ui/core/Popper 0.00% -0.03% 34,907 34,907 11,812 11,808
@material-ui/core/Textarea 0.00% 0.00% 5,327 5,327 2,291 2,291
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 15,898 15,898 5,771 5,771
@material-ui/core/useMediaQuery 0.00% +0.10% 🔺 2,106 2,106 974 975
@material-ui/lab +0.04% 🔺 +0.19% 🔺 141,612 141,666 42,722 42,802
@material-ui/styles 0.00% -0.01% 50,833 50,833 15,013 15,012
@material-ui/system 0.00% -0.03% 11,765 11,765 3,928 3,927
Button 0.00% 0.00% 85,621 85,621 25,588 25,588
Modal -0.84% -0.37% 79,901 79,229 24,011 23,922
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 50,908 50,908 11,210 11,210
docs.main -0.14% -0.04% 648,518 647,606 201,926 201,847
packages/material-ui/build/umd/material-ui.production.min.js +0.05% 🔺 +0.10% 🔺 293,909 294,065 82,489 82,569

Generated by 🚫 dangerJS against 07ef2e9

@oliviertassinari oliviertassinari added this to the v4 milestone Apr 17, 2019
@joshwooding joshwooding marked this pull request as ready for review April 18, 2019 15:34
const rootRef = React.useRef();
// can be removed once we drop support for non ref forwarding class components
const handleOwnRef = React.useCallback(ref => {
rootRef.current = ReactDOM.findDOMNode(ref);
Copy link
Member

Choose a reason for hiding this comment

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

I believe we can add the // StrictMode ready comment. If @eps1lon accepts it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Actually every findDOMNode that get's an instance from a ref should be strict-mode.

@@ -61,7 +68,7 @@ function TrapFocus(props) {
return;
}

if (!rootRef.current.contains(doc.activeElement)) {
if (rootRef.current && !rootRef.current.contains(doc.activeElement)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we warn if rootRef.current is not an instance of HTMLElement but the TrapFocus is enabled (like we do in the Popper's prop-types)? It's a broad question, it's no tight to this effort.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Probably better than checking for focus i.e. duck-typing.

@@ -61,7 +68,7 @@ function TrapFocus(props) {
return;
}

if (!rootRef.current.contains(doc.activeElement)) {
if (rootRef.current && !rootRef.current.contains(doc.activeElement)) {
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Probably better than checking for focus i.e. duck-typing.

const rootRef = React.useRef();
// can be removed once we drop support for non ref forwarding class components
const handleOwnRef = React.useCallback(ref => {
rootRef.current = ReactDOM.findDOMNode(ref);
Copy link
Member

Choose a reason for hiding this comment

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

Yes. Actually every findDOMNode that get's an instance from a ref should be strict-mode.

const ignoreNextEnforceFocus = React.useRef();
const sentinelStart = React.useRef();
const sentinelEnd = React.useRef();
const lastFocus = React.useRef();
const rootRef = React.useRef();
// can be removed once we drop support for non ref forwarding class components
const handleOwnRef = React.useCallback(ref => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Rather use instance.

Suggested change
const handleOwnRef = React.useCallback(ref => {
const handleOwnRef = React.useCallback(instance => {

A ref would be the the pointer-type i.e.

ref = { current: instance }
      ^^^^^^^^^^^^^^^^^^^^^ the ref as a pointer-like object
                 ^^^^^^^^ the actual instance
ref = instance => {}
      ^^^^^^^^^^^^^^ the ref as a callback that is fired every time the instance changes
      ^^^^^^^^ the instance

@oliviertassinari oliviertassinari merged commit 85e09ab into mui:next Apr 21, 2019
@joshwooding joshwooding deleted the remove-root-ref-usage branch April 21, 2019 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants