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

[Tabs] Forward refs #14714

Merged
merged 3 commits into from Mar 4, 2019
Merged

[Tabs] Forward refs #14714

merged 3 commits into from Mar 4, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Mar 2, 2019

Little bit different approach this time: Refactored tests first then implementation. Definitely still biased because I knew how the implementation would look like but still increased confidence in tests for me.

I need to investigate the shallow + disableLifeCycleIssue. This is causing enzyme to call componentDidMount if we wrap it in forwardRef.

Continues #14536

@eps1lon eps1lon added breaking change component: tabs This is the name of the generic UI component, not the React module! labels Mar 2, 2019
@eps1lon eps1lon added this to the v4 milestone Mar 2, 2019
it('should work server-side', () => {
const wrapper2 = shallow(
/* wrapping Tabs in forwardRef calls componentDidMount :(
it('should not have style server-side', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@oliviertassinari What issue is this trying to solve? I see that we currently move the indicator to the Tab on the first render but move it into the own render tree after it's mounted. I don't understand what this achieves. Could you elaborate what behavior we're expecting to see? Maybe I can come up with a better test for this behavior then.

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 that we should be using the server-side rendering API of enzyme, shallow was a poor fit for this test case. It's solving 3 problems, the root problem comes from the need of the browser layout API to position the indicator:

  • We want to display the indicator at the right location when doing the server-side rendering. We shouldn't have to wait for the client side reconciliation.
  • We don't want to see the indicator to disappear when switching between different pages client-side.
  • We want the indicator to be correctly positioned when the font is loaded and changes the tab width.

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find any. What's the ssr rendering API of enzyme?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Will look into it. Doesn't make any statements about lifecycles so not sure this helps.

.at(0)
.simulate('resize');

window.dispatchEvent(new window.Event('resize', {}));
Copy link
Member Author

Choose a reason for hiding this comment

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

Decouples test from specific implementation. We don't actually care how we listen to the resize event. Just that we listen to window.onResize. This should still pass if we switch to a useEffect and window.addEventListener.

@mui-pr-bot
Copy link

mui-pr-bot commented Mar 2, 2019

Details of bundle changes.

Comparing: 23549d4...5ebc9db

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +0.02% 🔺 +0.03% 🔺 371,758 371,844 91,928 91,954
@material-ui/core/Paper 0.00% 0.00% 76,930 76,930 19,372 19,372
@material-ui/core/Paper.esm 0.00% 0.00% 71,601 71,601 18,779 18,779
@material-ui/core/Popper 0.00% 0.00% 30,462 30,462 10,582 10,582
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 17,286 17,286 5,717 5,717
@material-ui/core/useMediaQuery 0.00% 0.00% 2,486 2,486 1,048 1,048
@material-ui/lab 0.00% 0.00% 184,505 184,505 50,732 50,732
@material-ui/styles 0.00% 0.00% 57,733 57,733 16,236 16,236
@material-ui/system 0.00% 0.00% 17,062 17,062 4,487 4,487
Button 0.00% 0.00% 99,633 99,633 26,634 26,634
Modal 0.00% 0.00% 98,871 98,871 26,227 26,227
colorManipulator 0.00% 0.00% 3,232 3,232 1,296 1,296
docs.landing 0.00% 0.00% 52,369 52,369 11,488 11,488
docs.main 0.00% 0.00% 678,998 678,998 206,245 206,245
packages/material-ui/build/umd/material-ui.production.min.js +0.02% 🔺 +0.02% 🔺 322,414 322,483 85,099 85,119

Generated by 🚫 dangerJS against 5ebc9db

Testing my own ability to write meaningful tests here.
Previously I converted to forwardRef and then fixed
tests. Let's see if we actually write better tests or still
do the same mistake. Better tests would result in minimal
breakage upon adding forwardRef.
@eps1lon eps1lon merged commit 5603723 into mui:next Mar 4, 2019
@eps1lon eps1lon deleted the feat/Tabs/forwardRef branch March 4, 2019 07:01
@oliviertassinari oliviertassinari changed the title [Tabs] forward refs [Tabs] Forward refs Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants