Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/sunny-sails-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react-brand': patch
---

Added `'use client'` directive to the `@primer/react-brand` entrypoints to support React Server Components.

Primer Brand components can now be imported into RSC-enabled frameworks like Next.js without manually adding `'use client'` to your files.
Comment thread
rezrah marked this conversation as resolved.
1 change: 1 addition & 0 deletions packages/e2e/integration-tests/fixtures/KitchenSink.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client'
import {useRef} from 'react'
import {
Hero,
Expand Down
1 change: 0 additions & 1 deletion packages/e2e/integration-tests/nextjs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client'
/*eslint-disable */
import TestFixture from '../integration-tests/fixtures/KitchenSink'

Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

export * from './css/stylesheets'

export * from './Hero'
Expand Down
19 changes: 19 additions & 0 deletions packages/react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {name: libraryName} = require('./package')
const path = require('path')
const postcssPresetEnv = require('postcss-preset-env')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const {sources, Compilation} = require('webpack')

module.exports = {
entry: './src/index.ts',
Expand Down Expand Up @@ -126,5 +127,23 @@ module.exports = {
new MiniCssExtractPlugin({
filename: './css/[name].css',
}),
// This is a custom plugin that preserves the 'use client' directive needed for RSC
// Do not remove it.
// Note: The UMD bundle (generated through this webpack config) doesn't preserve source 1:1.
// This is why we need to restore it using a plugin. This isn't needed with ESM, but needed for UMD.
{
apply(compiler) {
compiler.hooks.thisCompilation.tap('UseClientDirectivePlugin', compilation => {
compilation.hooks.processAssets.tap(
{name: 'UseClientDirectivePlugin', stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE}, // must run after terser
assets => {
if (assets['index.js']) {
compilation.updateAsset('index.js', new sources.ConcatSource("'use client';\n", assets['index.js']))
Comment thread
rezrah marked this conversation as resolved.
}
},
)
})
},
},
],
}
Loading