Skip to content

Commit f674224

Browse files
quantizorclaude
andauthored
fix: RSC edge case (#5665)
* fix: RSC style tags for extended components — correct href and include base CSS (#5663) - Fix spaces in <style href> that caused React 19 hydration warnings/failures when using styled() inheritance (e.g. styled(IconWrapper)) - Fix missing base component CSS in RSC output when only the extended component renders (base styles were injected into the sheet but never serialized into a <style> tag) - Emit a separate <style> tag per inheritance level with content-aware hrefs built from registered names (CSS content hashes), enabling React 19 deduplication of shared base styles while preventing incorrect dedup of dynamic variants - Preserve correct CSS ordering (base before extended) for proper specificity override behavior Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: bump bundle size limit to 12.35kB Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: add sandbox type augmentation test utilities Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: gitignore dist-test build output Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: use Set.forEach instead of for-of to avoid downlevelIteration TS error Co-Authored-By: Claude Opus 4.6 <[email protected]> * perf: eliminate RSC dead code from browser/standalone bundles Make IS_RSC a build-time constant (__IS_RSC__) replaced by rollup, enabling terser to eliminate all RSC-specific branches from browser and standalone builds (context fallbacks, style tag rendering, etc.). Server builds retain the runtime typeof React.createContext check. Reduces standalone bundle from 12.37KB to 12.11KB gzipped. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent b5bb591 commit f674224

15 files changed

Lines changed: 572 additions & 15 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"styled-components": patch
3+
---
4+
5+
fix: RSC style tags for extended components have correct href and include base CSS (#5663)
6+
7+
- Fix spaces in `<style href>` attribute that caused React 19 hydration failures when using `styled()` inheritance
8+
- Fix missing base component CSS in RSC output when only the extended component renders
9+
- Emit a separate `<style>` tag per inheritance level with content-aware hrefs, enabling React 19 deduplication of shared base styles
10+
- Preserve correct CSS ordering (base before extended) for proper specificity override behavior
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+
Reduce standalone/browser bundle size by making IS_RSC a build-time constant, enabling dead code elimination of RSC-specific branches

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ README.md
2323
.next
2424
*.tsbuildinfo
2525
**/next-env.d.ts
26+
**/dist-test
2627
.claude

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Mandates
1111
- React 16.8 compat
1212
- Always microbenchmark to validate optimizations
1313
- Optimize for low memory pressure and monomorphic functions
14+
- NEVER use `precedence` or `href` on `<style>` elements in `createGlobalStyle` — React 19 resource hoisting makes them persist after unmount. Regular styled components may use them since style persistence is intentional.
1415

1516
Agent rules
1617

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'styled-components';
2+
import type { ThemeInterface } from './test-augmentation-typeof';
3+
4+
declare module 'styled-components' {
5+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
6+
export interface DefaultTheme extends ThemeInterface {}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Reproduce the user's exact pattern: typeof a concrete theme object
2+
const myTheme = {
3+
colors: {
4+
primary: '#007bff',
5+
secondary: '#6c757d',
6+
},
7+
fontSize: {
8+
small: '12px',
9+
medium: '16px',
10+
},
11+
};
12+
13+
export type ThemeInterface = typeof myTheme;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test: does module augmentation actually populate DefaultTheme with typed properties?
2+
import { DefaultTheme } from 'styled-components';
3+
4+
function testAugmentation(theme: DefaultTheme) {
5+
// These should be typed from the augmentation in app/types/styled.d.ts
6+
const primary: string = theme.colors.primary;
7+
const small: string = theme.spacing.small;
8+
const fontFamily: string = theme.typography.fontFamily;
9+
10+
// This should error - 'nonexistent' doesn't exist on Theme
11+
// @ts-expect-error
12+
const bad = theme.nonexistent;
13+
14+
return { primary, small, fontFamily, bad };
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This simulates a consumer file that exposes DefaultTheme in its public API,
2+
// forcing TypeScript to emit the type in .d.ts output.
3+
import { DefaultTheme } from 'styled-components';
4+
5+
export function getThemeColor(theme: DefaultTheme) {
6+
return theme.colors.primary;
7+
}
8+
9+
export function makeTheme(): DefaultTheme {
10+
return {
11+
colors: { primary: '#fff', secondary: '#000', text: '#333', background: '#fff' },
12+
spacing: { small: '4px', medium: '8px', large: '16px' },
13+
typography: {
14+
fontFamily: 'sans-serif',
15+
fontSize: { small: '12px', medium: '14px', large: '18px' },
16+
},
17+
};
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": false,
10+
"outDir": "./dist-test",
11+
"declarationDir": "./dist-test",
12+
"esModuleInterop": true,
13+
"module": "esnext",
14+
"moduleResolution": "node",
15+
"resolveJsonModule": true,
16+
"isolatedModules": true,
17+
"jsx": "react-jsx",
18+
"composite": true,
19+
"declaration": true,
20+
"strictNullChecks": true
21+
},
22+
"include": ["**/*.ts", "**/*.tsx"],
23+
"exclude": ["node_modules"]
24+
}

‎packages/styled-components/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"files": [
131131
{
132132
"path": "./dist/styled-components.min.js",
133-
"maxSize": "12.3kB"
133+
"maxSize": "12.35kB"
134134
}
135135
]
136136
},

0 commit comments

Comments
 (0)