Skip to content

Commit c5e1c54

Browse files
committed
docs(v7): changesets, AGENTS, docs/
The 25 v7 changesets summarize the user-facing surface of the release at the appropriate semver level. AGENTS.md (and the CLAUDE.md symlink) carries the cross-cutting v7 rules and earned knowledge. docs/ collects topical writeups: rendering flow, single-output-path migration history, animation adapter map, TypeScript instantiation budget, rn-css compatibility tracker.
1 parent 062ec8b commit c5e1c54

36 files changed

Lines changed: 964 additions & 199 deletions

‎.changeset/attrs-ast-bridge.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"styled-components": minor
3+
---
4+
5+
Added a second argument to function-form `attrs((props, ast) => ...)` callbacks for bridging styles into props on third-party components. The `ast` accessor exposes `peek` (read a value) and `pop` (read and remove from the rendered style), and accepts either a CSS property name or a typed dot-separated theme path (e.g. `'color.red.500'`). Path autocomplete and value-type inference flow from your augmented theme.
6+
7+
```tsx
8+
import { Path } from 'react-native-svg';
9+
10+
const Icon = styled(Path).attrs((_props, ast) => ({
11+
fill: ast.pop('color'), // lift CSS decl into a prop
12+
stroke: ast.peek('palette.brand'), // read from theme via typed path
13+
}))`
14+
color: red;
15+
`;
16+
```
17+
18+
Both methods take an optional fallback as the second argument, returned when the value is missing. Works on web and native. When the callback's behavior is fully determined by static declarations the work folds into a one-time computation at construction so renders pay nothing extra.

‎.changeset/attrs-type-perf.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
Fixed a TypeScript regression where `styled(SomeComponent).attrs({...})` could trigger `TS2590: Expression produces a union type that is too complex to represent` on components with deeply-discriminated prop unions, notably antd's `Button`. Affected projects also see modestly faster type-checks; projects without complex unions see no measurable difference.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
React Native: `lab()` and `lch()` now produce correct colors when channels are written as percentages. `lab(50% 0 0)` resolves to mid-gray as expected, where it previously produced near-black. Per CSS Color L4, each space has its own range:
6+
7+
- `lab` L: 0%-100% maps to 0-100. a/b: 100% maps to ±125.
8+
- `lch` L: 0%-100% maps to 0-100. C: 100% maps to 0-150.
9+
- `oklab` L: 0%-100% maps to 0-1. a/b: 100% maps to ±0.4.
10+
- `oklch` L: 0%-100% maps to 0-1. C: 100% maps to 0-0.4.
11+
12+
Web is unaffected (browsers parse these notations natively).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"styled-components": major
3+
---
4+
5+
React Native: `createTheme()` now works exactly the way it does on web. Pass the returned object to `ThemeProvider`, reference leaves in your styled components, and the current theme resolves automatically.
6+
7+
```tsx
8+
import styled, { createTheme, ThemeProvider } from 'styled-components/native';
9+
10+
const theme = createTheme({
11+
colors: { bg: '#ffffff', text: '#111111' },
12+
});
13+
14+
const Card = styled.View`
15+
background-color: ${theme.colors.bg};
16+
border-color: ${theme.colors.text};
17+
`;
18+
19+
<ThemeProvider theme={{ colors: { bg: '#111', text: '#eee' } }}>
20+
<Card />
21+
</ThemeProvider>
22+
```
23+
24+
Nested `ThemeProvider`s on React Native deep-merge their theme objects so an inner override that only touches one leaf keeps the siblings it inherited; a child provider that sets `colors.text` keeps `colors.bg` from the ancestor. Web behavior is unchanged.

‎.changeset/drop-default-props.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"styled-components": major
3+
---
4+
5+
Styled components no longer honor `defaultProps`. React 19 removed `defaultProps` support from function components, so styled components can no longer inherit a parent's `defaultProps` either.
6+
7+
Migration: use `.attrs()` for prop defaults. The object form always wins over user-provided props (this is intentional, see the attrs FAQ). The function form lets user-provided props override the default:
8+
9+
```tsx
10+
// Before (v6, no longer applies in v7)
11+
const Button = styled.button``;
12+
Button.defaultProps = { type: 'button' };
13+
14+
// After (object form always wins)
15+
const Button = styled.button.attrs({ type: 'button' })``;
16+
17+
// After (user-provided overrides allowed)
18+
const Button = styled.button.attrs<{ type?: string }>(p => ({
19+
type: p.type ?? 'button',
20+
}))``;
21+
```
22+
23+
For a default theme, wrap the tree in `<ThemeProvider theme={...}>` instead.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
Empty CSS custom property values are now preserved.
6+
7+
`--my-prop: ;` is a legitimate CSS declaration; the empty value is part of the Custom Properties spec and is used by patterns like scroll-driven animations as a "guaranteed-invalid" sentinel. Previously these declarations were silently dropped from the rendered output, which broke setups like:
8+
9+
```css
10+
@keyframes shadow-toggle {
11+
from, to { --shadow: ; }
12+
}
13+
```
14+
15+
They now render as authored. Empty values for non-custom properties (e.g. `color: ;`) continue to be dropped, since those are still invalid CSS.
16+
17+
Note: components that author `--prop: ;` will get a new class name on upgrade since the emitted CSS now differs. Typical apps are unaffected.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"styled-components": major
3+
---
4+
5+
Removed the `disableCSSOMInjection` prop on `<StyleSheetManager>` and the `SC_DISABLE_SPEEDY` / `REACT_APP_SC_DISABLE_SPEEDY` environment variables. Added a new `extractCSS` export.
6+
7+
Browser builds now always use the same fast injection path that production has used by default for years. There's no longer a knob to switch into a slower text-based mode at runtime, and dev and production now behave identically.
8+
9+
If you were using the toggle to make CSS visible as text (for static-render pipelines, micro-frontend cloning, embedding into iframes or Shadow DOM, or extraction tooling), call the new `extractCSS()` function after render to get the current CSS as a plain string:
10+
11+
```js
12+
import { extractCSS } from 'styled-components';
13+
14+
// after rendering
15+
const css = extractCSS();
16+
```
17+
18+
The result is plain CSS without the rehydration markers used by `ServerStyleSheet`, so it can be injected directly into another document, stamped into a cloned DOM tree, or written to disk.

‎.changeset/global-style-useid.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"styled-components": major
3+
---
4+
5+
Mounting the same `createGlobalStyle` component multiple times now emits its CSS only once. Previously each mount produced its own copy of the stylesheet rules. Rendering output stays byte-stable across SSR, client, and Server Components.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
Inlined the prop validator that decides which props reach the underlying DOM element. styled-components no longer pulls `@emotion/is-prop-valid` from npm; the same validation logic ships inside the library itself. Consumers see a smaller dependency tree and a slightly smaller installed footprint, with identical behavior.
6+
7+
If you were already importing `isPropValid` from `@emotion/is-prop-valid` directly elsewhere in your app, that continues to work; this change only affects what styled-components itself depends on.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
Fixed selector resolution for nested rules whose parent contains a comma inside `:is()`, `:where()`, `:has()`, or an attribute selector.
6+
7+
Previously a parent like `:is(&:hover, .parent:hover &) .child` containing a nested rule would produce nonsense output where the nested selector got injected into the first arm of the `:is(...)` call. For example:
8+
9+
```jsx
10+
const Card = styled.div`
11+
:is(&:hover, .parent:hover &) .child {
12+
color: red;
13+
.grandchild { color: blue; }
14+
}
15+
`;
16+
```
17+
18+
The grandchild rule used to compile to `:is(.card-class:hover .grandchild, .parent:hover .card-class) .child .grandchild { color: blue; }`, where the `.grandchild` token leaked into the `:is()` parens. It now compiles correctly to `:is(.card-class:hover, .parent:hover .card-class) .child .grandchild { color: blue; }`. The same fix applies to commas inside `[attr*="a,b"]` and other paren/bracket-protected contexts.

0 commit comments

Comments
 (0)