Skip to content

fix: component selectors for memo, function wrappers and Preact, server manager options, prerelease job - #5867

Merged
quantizor merged 6 commits into
6.xfrom
fix/6x-review-findings
Nov 6, 2026
Merged

quantizor merged 6 commits into
6.xfrom
fix/6x-review-findings

Conversation

@quantizor

@quantizor quantizor commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Three fixes for styles that came out wrong with no useful error, plus a repair to the 6.x prerelease job.

Component selectors

${Box}:hover { ... } produces Box's selector for:

  • Any styled component under preact/compat. The selector came out as [object Object], or the render threw.
  • A React.memo or function wrapper that has the styled component's statics hoisted onto it. A memo wrapper's fields were written out as CSS declarations, and a function wrapper was called as an interpolation.

A forwardRef wrapper with hoisted statics is unchanged by this PR: styled() treats it as the styled component itself and skips the wrapper's own render.

Server StyleSheetManager

In a server component, <StyleSheetManager stylisPlugins={[]} namespace="#scope"> drops the plugins and keeps the namespace, and the same goes for enableVendorPrefixes, matching client components.

A server manager with a stable plugins array plus namespace or enableVendorPrefixes reuses its compiled stylis instance across renders instead of building a new one each time, and stylisPlugins={[]} on its own no longer builds one at all.

Prerelease job

The 6.x Release workflow's prerelease job failed with Cannot find module 'semver', so no 6.x prerelease has published since the move to pnpm 12. The script's imports are now declared at the repo root. The script runs to completion locally against the pending changesets; the job itself only runs after a merge to 6.x.

The lockfile also moves the dev-only styled-components peer of babel-plugin-styled-components from 6.5.3 to 6.6.0, which pnpm refreshes on any lockfile change. Nothing published changes.

Cost

Bundle size, gzip -9 bytes:

Bundle Before After Change
browser ESM 14,004 14,004 0
browser CJS 14,150 14,161 +11
server ESM 15,592 15,591 -1
server CJS 15,738 15,733 -5
standalone min 12,889 12,906 +17

Render time is unchanged within noise: the geometric mean is 0.998x across 57 server component and client benchmark rows, median of 6 rounds on one machine, run from source. Rows outside ±3% fall on both sides, including a plain React control at 0.92x.

Testing

Web, native, and build suites pass, with new tests for each selector case (unit and rendered), each manager option, instance reuse across requests, and global styles that refer to a component staying static. The preact/compat case is tested with a stand-in that gives forwardRef Preact's return shape, not with Preact itself.

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8a04c33

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Component selectors for memo and Preact — flatten now treats any object carrying styledComponentId as a selector (which covers a memo wrapper with hoisted statics, whose $$typeof stays react.memo) and checks isStyledComponent before invoking a function carrier, matching Preact compat's forwardRef shape.
  • Server StyleSheetManager options with stylisPlugins={[]} — the RSC path keeps a namespace or enableVendorPrefixes passed alongside an empty plugin list instead of short-circuiting to the default stylis instance, so server and client now hash the same class names.
  • Prerelease notes dependencies — @changesets/read and semver declared at the repo root so the 6.x prerelease job can resolve the script's imports; the lockfile picks up the intended babel-plugin-styled-components peer refresh alongside.
  • Also reviewed the docs/rsc-style-injection.md update and both patch changesets.

Verification on this head: full web suite (1004 tests), native suite (45 tests), and both new RSC manager cases pass; reverting flatten.ts to base fails the memo and both Preact carrier tests, and reverting StyleSheetManager.tsx to base reproduces the dropped namespace with a divergent server class name. The changelog state confirms the empty-plugins bug shipped in 6.6.0, so the separate changesets are appropriate.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@quantizor quantizor changed the title fix: component selectors for memo and Preact, server manager options, prerelease job fix: component selectors for memo, function wrappers and Preact, server manager options, prerelease job Nov 6, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor test-strengthening suggestion inline.

Reviewed changes

Reviewed the two commits since the last pullfrog review, which consolidated the selector brand check and reworked the server manager's stylis resolution.

  • Shared brand check for component selectors — hasStyledComponentBrand now backs both the function and object carrier paths in flatten, so preact/compat's function-shaped components and brand-hoisting function HOCs emit .<styledComponentId> instead of being invoked as interpolations, while isStyledComponent keeps the $$typeof requirement that chain folding relies on.
  • Server manager stylis reuse — the RSC resolution is simplified to inherit / plugins-with-options / options-without-plugins, so a manager with a stable plugins array plus namespace or enableVendorPrefixes reuses one cached instance across renders instead of rebuilding it, and a test locks that identity.
  • Reverted the isStaticRules exemption — css() already resolves carriers to class selectors, so the exemption was dead; the net PR change to that module is now a new unit suite only.
  • Selector test consolidation — the two Preact and memo selector cases became one parameterized test with a jest.spyOn(React, 'forwardRef') helper, removing two @ts-expect-error monkey patches, and both changesets were reworded.

Verified on this head: jest -c jest.config.main.js (61 suites / 1010 tests), jest -c jest.config.native.js (45 tests), and the package tsc --noEmit all pass, with pnpm install --frozen-lockfile clean so the prerelease devDependency additions match the lockfile.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Reviewed the two commits since the prior pullfrog review, which are a formatting pass and the test strengthening that closes the remaining inline suggestion.

  • RSC stylis reuse test no longer passes vacuously — styled.rsc.test.tsx now imports mainStylis and asserts the instance read through useStyleSheetContext() is not the default, so the test fails if the manager never writes its override, not only when it rebuilds the instance.
  • Formatting reflow — the withFunctionForwardRef helper body in basic.test.tsx was reflowed by Prettier; no behavior change.

Verified on this head: jest -c jest.config.main.js src/constructors/test/styled.rsc.test.tsx passes 86/86. I also mutation-checked the new assertion — resolving mainStylis from the plugins branch makes both reuse rows fail at that line — so it now guards the failure class it was written for, and the prior thread can stay resolved.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

Reviewed the two commits since the prior pullfrog review, which act on its one inline suggestion and reformat a test file.

  • Strengthened the server stylis reuse test — the test now asserts the manager's stylis instance is not the default mainStylis, so it fails when a stylisPlugins + namespace / enableVendorPrefixes manager drops its override entirely, not only when it rebuilds per request.
  • Reformatted basic.test.tsx — no behavior change.

Confirmed the new assertion has teeth: suppressing the manager's override in StyleSheetManager.tsx (so every read is the default instance) fails both reuse cases with the new line and would have passed without it. The full RSC suite (86 tests) and basic.test.tsx (36 tests) pass on this head.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@quantizor
quantizor merged commit 4bfc2cb into 6.x Nov 6, 2026
8 checks passed
@quantizor
quantizor deleted the fix/6x-review-findings branch November 6, 2026 16:40
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.

1 participant