Skip to content

TextField rerendering causes global styles to recalculate on each keystroke with SC #28051

Closed
@0xF013

Description

@0xF013

When using TextField and @material-ui/styled-engine-sc as a controlled input (in a render prop?), this part https://github.com/mui-org/material-ui/blob/7bdf8a35299fa4a7e9ae97eff5f3b074170c38ef/packages/material-ui/src/InputBase/InputBase.js#L486 causes the styled component blob <style> tag to redraw on each keystroke. I would assume that the styled-components' implementation of global styles is less efficient than emotion's (their source code uses a useLayoutEffect that flickers on each prop update).

image

Video: https://vimeo.com/manage/videos/594582087

While it's not really noticeable in a demo, it scales at least linearly with the number of styles in a project.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Expected Behavior 🤔

Steps to Reproduce 🕹

Steps:

  1. https://codesandbox.io/s/styled-components-forked-crstj?file=/src/demo.jsx
  2. Inspect the input and follow a style into the inspect mode
  3. Start typing in the input
  4. Notice the style tag flickering.
  5. Notice, at the bottom of the tag, the styles for the autofill flickering

Context 🔦

Your Environment 🌎

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions