-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[InputBase] Fix autofill issue #28070
Conversation
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.
Seems like this is a footgun for GlobalStyles
in general with styled-components
.
We should document this for GlobalStyles
. Have you checked the other uses of GlobalStyles
in the codebase?
Do both issues require this complete change or did you group two changes that can independently fix either issue?
Not sure what we can do about this.. :\
This and the About the documentation, agree, I will create a PR with a note in the documentation for the
I've grouped the two changes, mostly because they are both affected by the global styles and they are both part of the v5 milestone. |
Ok. Could you make it obvious in the PR description which change fixes which problems? I'd have to guess right now but guessing is risky long-term. |
Sure, makes sense. Updated. |
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.
👍
@@ -483,12 +493,7 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) { | |||
|
|||
return ( | |||
<React.Fragment> | |||
<GlobalStyles | |||
styles={{ |
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.
Just learned that @babel/plugin-transform-constant-elements
deopts mutable props. This unlocks a bunch of optimizations actually since we treat props as immutable all the time. Will investigate in a follow-up.
@mnajdova stumbled across this PR when searching. Our app is rendering a lot of text fields at once and this is injecting a global style in the This is causing an initial render performance issue when the number of text fields to render at once is pretty big. Is there any way to make this only inject once? |
Sorry for the late response @bryan-hunter . We want the components to be able to be used in isolation without needing to setup anything else so by default I don't think so. Maybe we could add a property on the component that if set, would just not render the global styles, assuming the developers already rendered those at the top of their App. Would something like this work for your team? Would you like to submit a PR? Also would be useful to see some benchmark that would show the perf difference we would have with this. |
I will attempt a PR now :) I patched material-ui to remove the GlobalStyle and added it to createTheme with
if anyone needs a solution in the interim |
1. Autofill detection not working in production
Fixes #26449
The empty keyframes are being removed in production by emotion. Adding an
from { display: 'block' }
fixes the issue. I've decided to go with this style, as it is already defined in the styles for theInputBase
component.2. TextField rerendering causes global styles to recalculate on each keystroke with
styled-components
Fixes #28051
The GlobalStyles are now hoisted in a static variable, as otherwise the <style> tag redraw on each keystroke when the Input component is rendered for example as a callback, see #28051
Reproduction and verification of the fixes
Steps:
Previous:
Codesandbox link: https://codesandbox.io/s/ecstatic-wilbur-710ny?file=/src/App.js
Production build link: https://csb-710ny.netlify.app/?
Now:
Codesandbox link: https://codesandbox.io/s/upbeat-dream-5nttz?file=/package.json
Production build link: https://csb-5nttz.netlify.app/?
Previous:
https://codesandbox.io/s/styled-components-forked-crstj?file=/src/demo.jsx
Now:
https://codesandbox.io/s/styled-components-forked-gwepq?file=/src/demo.jsx