Skip to content

Server component styles containing >, quotes, or & are HTML-escaped on Next.js 13.5 and 14 #5824

Done

Description

@quantizor

Server components on Next.js 13.5 and 14 can render broken CSS on first load when a style contains a child combinator, a quoted value, or an ampersand.

What happens

styled-components renders server component styles as an inline <style> element. Next.js 13.5 and 14 bundle a React 18.3 canary whose server renderer HTML-escapes text inside <style>, so the server HTML contains, for example:

<style data-styled="">.a &gt; .b{content:&quot;x&quot;}</style>

Browsers read <style> contents as raw text and never decode entities there, so .a &gt; .b is an invalid selector and the rule is dropped. React 19 (Next.js 15 and later) does not escape these characters inside <style>, so newer versions are unaffected.

Minimal repro

// app/page.tsx on next@14, no 'use client'
import styled from 'styled-components';

const List = styled.ul`
  & > li {
    color: red;
  }
  &::before {
    content: "list";
  }
`;

export default function Page() {
  return (
    <List>
      <li>should be red</li>
    </List>
  );
}

View the page source: the > and quotes inside the <style> arrive as &gt; and &quot;.

Notes

So far I've confirmed this in the server HTML only; it's worth checking whether a client-side navigation (which renders the style from React's payload instead of HTML) shows the correct styles. ServerStyleSheet output is unaffected because it renders style text through a path the renderer doesn't escape. A fix would render the text the same way for older React versions while still preventing a style value from closing the tag.

Activity

  1. pullfrog commented on Oct 10, 2026

    @pullfrog
  2. added a commit that references this issue on Nov 24, 2026
    7831e15
  3. quantizor commented on Nov 25, 2026

    @quantizor
    ContributorAuthor

    Fixed in 6.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions