Skip to content

Bug: stylesheets that use precedence are significantly slower to render at scale #32806

@RJWadley

Description

@RJWadley

React version: 19.0.0, 19.1.0

Steps To Reproduce

  1. Render at least two precedence levels, for example 'a' and 'b' so that react can insert our stylesheets into the head rather than inline.
  2. Render lots of style elements into 'a' (your first precedence level, the important part is that react inserts our stylesheets into the head) and observe performance. Compare this to rendering without any precedence at all.

Link to code example:

Here's a codesandbox demonstrating the basic issue:
https://codesandbox.io/p/sandbox/react-style-perf-t7w9qr
Or a github repository, if you prefer:
https://github.com/RJWadley/react-style-perf

The current behavior

Seems like each style tag is handled independently with very little optimization - which is probably fine if you only load one or two stylesheets but doesn't work well for larger amounts of styling. In the attached example, you should also notice that every time we toggle our styles with precedence our performance gets worse and worse.

Here's a real example of render performance on my M1 mac pro. This isn't from the attached example, but is the same issue just at a larger scale: Image

Zooming in, most of the performance hit seems to come from query selectors and from actually inserting each stylesheet.
Image

The expected behavior

Stylesheets should ideally render in similar time regardless of precedence.

Related: #30739

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions