Skip to content

Add support for React Server Components (RSC), fix Rollup duplicate 'use client' directives, prepare beta release#285

Merged
colinrotherham merged 25 commits intomainfrom
rollup-directives
Oct 13, 2025
Merged

Add support for React Server Components (RSC), fix Rollup duplicate 'use client' directives, prepare beta release#285
colinrotherham merged 25 commits intomainfrom
rollup-directives

Conversation

@colinrotherham
Copy link
Collaborator

@colinrotherham colinrotherham commented Oct 9, 2025

This PR adds support for React Server Components (RSC)

Our dot-separated Card, Card.Heading, Card.Description style currently has RSC issues as shown in:

As a workaround, I've exported CardHeading and CardDescription to resolve this, otherwise dynamically assigned child properties become undefined using Next.js App Router:

 ⨯ [Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.] {

I've also swapped rollup-plugin-preserve-directives for rollup-preserve-directives

The current plugin is causing duplicate 'use client' directives to be added:

./node_modules/nhsuk-react-components/dist/esm/components/content-presentation/table/TableSectionContext.js
   ╭─[/path/to/project/node_modules/nhsuk-react-components/dist/esm/components/content-presentation/table/TableSectionContext.js:4:1]
Error:   × The "use client" directive must be placed before other expressions. Move it to the top of the file to resolve this issue.
1 │ "use client";
2 │ import { createContext } from 'react';
3 │ 
4 │ 'use client';
   · ─────────────
5 │ var TableSection;
6 │ (function (TableSection) {
7 │     TableSection[TableSection["NONE"] = 0] = "NONE";

@colinrotherham colinrotherham changed the title Fix Rollup duplicate 'use client' directives Fix Rollup duplicate 'use client' directives, prepare beta release Oct 9, 2025
@colinrotherham colinrotherham changed the title Fix Rollup duplicate 'use client' directives, prepare beta release Add support for React Server Components (RSC), fix Rollup duplicate 'use client' directives, prepare beta release Oct 13, 2025
@colinrotherham
Copy link
Collaborator Author

See sample project for a thorough Next.js SSR example:
https://github.com/colinrotherham/nhsuk-react-components-nextjs-app

@sonarqubecloud
Copy link

@colinrotherham colinrotherham added this pull request to the merge queue Oct 13, 2025
Merged via the queue into main with commit 8d13ff4 Oct 13, 2025
3 checks passed
@colinrotherham colinrotherham deleted the rollup-directives branch October 13, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments