styled-components / styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress šŸ’…
https://styled-components.com
MIT License
40.11k stars 2.48k forks source link

`css` props are not applied within the server component. #4278

Open sohnjunior opened 2 months ago

sohnjunior commented 2 months ago

Environment

System:

Reproduction

codesandbox

snippets overview

"use client";
import { PropsWithChildren } from "react";
import styled, { type CSSProp } from "styled-components";

export const Container = styled.div`
  box-sizing: content-box;
`;

interface AnotherContainerProps {
  css?: CSSProp;
}

export function AnotherContainer({
  css,
  children,
}: PropsWithChildren<AnotherContainerProps>) {
  return <div css={css}>{children}</div>;
}
import { Container, AnotherContainer } from "../components/container";

export default function Page() {
  return (
    <div>
      <Container css={{ color: "red" }}>content1</Container>
      <AnotherContainer css={{ color: "red" }}>content2</AnotherContainer>
    </div>
  );
}

I defined two components: Container and AnotherContainer. One returns styled.div as is and the other is a wrapped component.

I expect that the CSS prop should be applied appropriately in both cases, but the CSS prop is applied only in AnotherContainer.

į„‰į…³į„į…³į„…į…µį†«į„‰į…£į†ŗ 2024-03-12 į„‹į…©į„’į…® 7 52 59

Container component throws the following error message: į„‰į…³į„į…³į„…į…µį†«į„‰į…£į†ŗ 2024-03-12 į„‹į…©į„’į…® 7 49 45

Expected Behavior

Both Container and AnotherContainer should apply css prop properly.

Actual Behavior

Only AnotherContainer applied css prop.