Skip to content

fix(react): improve specificity for styled lazy components - #1480

Merged
Anber merged 1 commit into
callstack:masterfrom
Anber:anber/fix-lazy-styled-specificity
Jun 23, 2026
Merged

fix(react): improve specificity for styled lazy components#1480
Anber merged 1 commit into
callstack:masterfrom
Anber:anber/fix-lazy-styled-specificity

Conversation

@Anber

@Anber Anber commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1415.

Summary

  • Detect React.lazy targets during styled extraction.
  • Preserve wrapper override specificity by duplicating the generated wrapper class when the lazy target metadata cannot be resolved.
  • Add a regression test for styling a lazy component.

Why

Linaria normally emits chained selectors when styling another styled component, for example .Wrapper.Base, so wrapper styles can override base styles.

For React.lazy targets, the wrapped component metadata is hidden behind the lazy boundary and is not available synchronously during extraction. That left the wrapper rule with only one generated class, so CSS loaded later by the lazy chunk could override it.

Validation

  • pnpm --filter @linaria/react test
  • pnpm --filter @linaria/testkit test -- babel.test.ts -t "adds specificity when wrapping a lazy component"
  • pre-commit hook: check:all, lint, sp:check

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9547ef9

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

This PR includes changesets to release 1 package
Name Type
@linaria/react 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

@Anber
Anber marked this pull request as ready for review June 23, 2026 10:24
@Anber
Anber merged commit be435e4 into callstack:master Jun 23, 2026
5 checks passed
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.

Lazy loaded Linaria components have wrong specificity when decorated with styled()

1 participant