Skip to content

perf: fix createGlobalStyle test performance regression - #5679

Merged
quantizor merged 1 commit into
mainfrom
fix/global-style-test-perf
Mar 19, 2026
Merged

quantizor merged 1 commit into
mainfrom
fix/global-style-test-perf

Conversation

@quantizor

Copy link
Copy Markdown
Contributor

Summary

  • Move synchronous renderStyles to only execute on server/RSC paths — in client mode the useLayoutEffect already handles this, eliminating double work on every render
  • Remove removeGlobalStyleTag from client cleanup — it was doing querySelectorAll for data-styled-global tags on every unmount, which only exist after SSR hydration and are a no-op DOM query in test environments
  • Bundle size decreased slightly (12.08KB vs 12.14KB gzip) due to dead code elimination

Test plan

  • All 501 web tests pass
  • Build passes with bundlewatch
  • Test suite runs ~20% faster (1.6s vs 2.0s)
  • Manual verification with a large test suite using createGlobalStyle

Fixes #5674

Two changes to eliminate unnecessary overhead in client/test environments:

1. Move synchronous renderStyles to only run on server/RSC paths. In
   client mode, the useLayoutEffect already handles style rendering,
   so the synchronous call during component execution was double work.

2. Remove removeGlobalStyleTag from client cleanup. This function does
   querySelectorAll for data-styled-global tags, which only exist after
   SSR hydration. In pure client/test environments it was a no-op DOM
   query on every global style unmount. globalStyle.removeStyles already
   handles client-side StyleSheet cleanup.

Fixes #5674
@changeset-bot

changeset-bot Bot commented Mar 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ff23908

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
styled-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@quantizor
quantizor marked this pull request as ready for review March 19, 2026 06:10
@quantizor
quantizor merged commit db4f940 into main Mar 19, 2026
5 checks passed
@quantizor
quantizor deleted the fix/global-style-test-perf branch March 19, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance degradation with tests and 6.3.x

1 participant