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

[TextField] Update labelWidth at each render #17583

Closed
wants to merge 4 commits into from
Closed

[TextField] Update labelWidth at each render #17583

wants to merge 4 commits into from

Conversation

neon98
Copy link
Contributor

@neon98 neon98 commented Sep 26, 2019

Closes #17355

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 26, 2019

Details of bundle changes.

Comparing: 274aeb8...29c2da1

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +0.01% 🔺 +0.01% 🔺 332,283 332,314 90,694 90,699
@material-ui/core/Paper 0.00% 0.00% 68,882 68,882 20,523 20,523
@material-ui/core/Paper.esm 0.00% 0.00% 62,319 62,319 19,261 19,261
@material-ui/core/Popper 0.00% 0.00% 28,397 28,397 10,159 10,159
@material-ui/core/Textarea 0.00% 0.00% 5,082 5,082 2,136 2,136
@material-ui/core/TrapFocus 0.00% 0.00% 3,766 3,766 1,596 1,596
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16,348 16,348 5,818 5,818
@material-ui/core/useMediaQuery 0.00% 0.00% 2,488 2,488 1,050 1,050
@material-ui/lab 0.00% 0.00% 143,344 143,344 43,790 43,790
@material-ui/styles 0.00% 0.00% 51,641 51,641 15,350 15,350
@material-ui/system 0.00% 0.00% 15,581 15,581 4,341 4,341
Button 0.00% 0.00% 78,900 78,900 24,093 24,093
Modal 0.00% 0.00% 14,542 14,542 5,113 5,113
Portal 0.00% 0.00% 2,907 2,907 1,318 1,318
Rating 0.00% 0.00% 70,185 70,185 21,930 21,930
Slider 0.00% 0.00% 75,326 75,326 23,259 23,259
colorManipulator 0.00% 0.00% 3,835 3,835 1,519 1,519
docs.landing 0.00% 0.00% 54,267 54,267 14,344 14,344
docs.main 0.00% 0.00% 582,093 582,093 186,334 186,334
packages/material-ui/build/umd/material-ui.production.min.js +0.01% 🔺 +0.01% 🔺 303,129 303,158 87,208 87,215

Generated by 🚫 dangerJS against 29c2da1

@eps1lon
Copy link
Member

eps1lon commented Sep 26, 2019

Thanks for working on this.

Could you explain what you're trying to fix? Preferably with a test case or a codesandbox to illustrate the issue?

@neon98
Copy link
Contributor Author

neon98 commented Sep 26, 2019

Hey @eps1lon ! I am trying to solve #17355. Codesandbox is given in the issue description.

@oliviertassinari oliviertassinari changed the title [TextField] fix missing notch in outlined TextField [TextField] Update labelWidth at each render Sep 26, 2019
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Sep 26, 2019
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

That causes reflow on every render. This should not be accepted in this form.

@@ -93,13 +93,18 @@ const TextField = React.forwardRef(function TextField(props, ref) {

const [labelWidth, setLabelWidth] = React.useState(0);
const labelRef = React.useRef(null);
React.useEffect(() => {

const updateOutlinedLabel = React.useCallback(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary

@oliviertassinari
Copy link
Member

@eps1lon Do you think that the reflow of the label can impact performance? Remembers me #11673.

@eps1lon
Copy link
Member

eps1lon commented Sep 26, 2019

@eps1lon Do you think that the reflow of the label can impact performance? Remembers me #11673.

As far as I know reflow affects the whole page. Since this change only fixes one particular issue while affecting perf for everyone else I would take this slow.

At least add a test that only runs in the browser (that's why we have them) so that we can swap out the implementation easily.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 26, 2019

@eps1lon I have looked at the performance cost of this reflow. I have used one controlled text field component in dev mode. After 8 change events, I had 2ms spent in this reflow vs 24ms of rendering and 93 ms of scripting (will be less in prod). Early results seem to indicate the overhead is negligible. Would you confirm?

@oliviertassinari
Copy link
Member

@neon98 it seems that you have deleted your forked repository ⚠️

@neon98
Copy link
Contributor Author

neon98 commented Sep 26, 2019

@oliviertassinari yes! would it be a problem?

@mbrookes
Copy link
Member

@neon98 It means that this PR can't be revised.

@eps1lon
Copy link
Member

eps1lon commented Sep 27, 2019

Yeah this is a scary change. 10% of rendering time in dev is not negligible in my book but if you say so then I won't object.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 27, 2019

With more hindsight, I'm not sure what path we should take with this issue. I have looked more closely at the performance impact, with more samples. The "recalculate styles phase" introduced by this logic costs between 8% and 3%. Interestingly the TextareaAutosize has also a reflow logic that seems to cost more. Also, if somebody provides a rich label, the reflow is present (but not forced, users can dodge it with memoization). Maybe it's not important, is the brute force approach fast enough?

They are two observable APIs that we could potentially leverage IntersectionObserver and ResizeObserver but they are not supported everywhere.

No matter what, we need a new limitation section in the text field documentation for SSR: #17305 (with a background color on the label that matches the main background).

@eps1lon What would you recommend?

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 27, 2019

Alright, I'm closing. I think that we should focus on a limitation docs update and wait to get more upvotes for the problem in #17355.

@neon98 Thank you for taking the time to open a pull request. If you want to continue the topic, you could focus on #17305. Otherwise, we are handling, what I think is close to an edge case here, it's not incredibly important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field 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.

[TextField] Outlined label gap is missing when first rendered hidden
5 participants