Repository navigation
Description
First, a quick question: is Preact officially supported? I couldn't find a clear answer in the docs. We're running a production app that uses Preact and styled-components, and we've hit a regression migrating from v5 to v6.
Environment
styled-components: 6.4.1 (broken) / 5.3.11 (works)preact: 10.29.1vite: 5.4.1- Node: 22.22.0
Also tested with latest React — both versions of styled-components work fine with it.
Reproduction
import React from "react";
import styled from "styled-components";
const Box = styled.div`
background: "#222";
color: "#fff";
padding: "2px 6px";
`;
const Box1 = styled(Box)`
padding: 20px;
margin: 8px 0;
background: #c8e6ff;
border: 4px solid #0055cc;
`;
const Box2 = styled(Box1)`
border-color: #cc0077;
background: #e6660b;
`;
const Box3 = styled(Box2)`
color: darkblue;
font-weight: bold;
`;
export default function App() {
return (
<div>
<h1>styled-components v6 — <code>as</code> prop in chains</h1>
<h2>1 extension + as="section" (✓ works)</h2>
<Box1 as="section">Content</Box1>
<h2>2 extensions + as="section" (❌ broken: Box1 styles missing)</h2>
<Box2 as="section">Content</Box2>
<h2>3 extensions + as="section" (❌ broken: Box1 and Box2 styles missing)</h2>
<Box3 as="section">Content</Box3>
<h2>3 extensions WITHOUT as="section" (✓ works: all styles applied)</h2>
<Box3>Content</Box3>
</div>
);
}Setup uses @preact/preset-vite which aliases react → preact/compat.
Steps to reproduce
- Set up a Vite project with
preactandstyled-components@6, using@preact/preset-vite - Create a styled-component chain of 2+ extensions (
styled(styled(styled.div))) - Render the outermost component with
as="section"(or any valid tag) - Styles from intermediate chain levels are not applied
Here are screenshots for SC5 and SC6 on Preact:
working on SC5
SC6 drops intermediate styles
Expected behavior
All styles from every level of the chain are applied, regardless of whether as is used — consistent with the behavior without as, and with styled-components v5.
Actual behavior
When as is passed to a component that extends 2 or more styled-components, styles from the intermediate chain levels are dropped. Without as, the same component renders correctly with all styles applied.
This regression does not occur with styled-components v5 (tested on 5.3.11) or without Preact (plain React is unaffected).
Workaround
Instead of relying on as to change the root element, use a custom renderAs prop on the underlying component and pass it explicitly:
const Box = ({ renderAs = "div", className, children }) =>
React.createElement(renderAs, { className }, children);
const Box3 = styled(styled(styled(Box))`...`)`...`;
// ❌ broken — `as` is consumed by styled-components, Box never receives it
<Box3 as="section" />
// ✓ workaround — renderAs is a plain prop, not intercepted by SC
<Box3 renderAs="section" />
Activity
quantizor commentedon May 14, 2026
Could you try
[email protected]when you get a chance?rbrochot commentedon May 18, 2026
Looks good to me with
[email protected]Thanks a lot, for this issue, and your work in general :)
quantizor commentedon May 19, 2026
Fix released with 6.4.2 :)