Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for react, react-dom 19.x #5240

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions examples/react-19/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const path = require('node:path')

module.exports = {
extends: ['plugin:@next/next/recommended'],
settings: {
next: {
rootDir: path.join(__dirname, 'src'),
},
},
rules: {
'react/react-in-jsx-scope': 'off',
},
}
5 changes: 5 additions & 0 deletions examples/react-19/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
24 changes: 24 additions & 0 deletions examples/react-19/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "example-react-19",
"version": "0.0.0",
"private": true,
"scripts": {
"clean": "rimraf .next",
"build": "next build",
"develop": "next",
"start": "next start",
"type-check": "tsc --noEmit"
},
"dependencies": {
"@primer/react": "37.3.0",
"next": "15.0.2",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"styled-components": "5.x",
"typescript": "^5.6.3"
},
"devDependencies": {
"@next/eslint-plugin-next": "15.0.2",
"rimraf": "^5.0.5"
}
}
23 changes: 23 additions & 0 deletions examples/react-19/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {BaseStyles, ThemeProvider} from '@primer/react'
import {StyledComponentsRegistry} from './registry'

export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({children}: {children: React.ReactNode}) {
return (
// Note: the focus-visible polyfill adds additional attributes to `html`
// that cause hydration mismatch errors
<html lang="en" suppressHydrationWarning>
<body>
<StyledComponentsRegistry>
<ThemeProvider>
<BaseStyles>{children}</BaseStyles>
</ThemeProvider>
</StyledComponentsRegistry>
</body>
</html>
)
}
5 changes: 5 additions & 0 deletions examples/react-19/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Button} from '@primer/react'

export default function IndexPage() {
return <Button>Hello world</Button>
}
24 changes: 24 additions & 0 deletions examples/react-19/src/app/registry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client'

import {useServerInsertedHTML} from 'next/navigation'
import React, {useState} from 'react'
import {ServerStyleSheet, StyleSheetManager} from 'styled-components'

/**
* @see https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components
*/
export function StyledComponentsRegistry({children}: React.PropsWithChildren) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())

useServerInsertedHTML(() => {
const styles = styledComponentsStyleSheet.getStyleElement()
styledComponentsStyleSheet.instance.clearTag()
return <>{styles}</>
})

if (typeof window !== 'undefined') return <>{children}</>

return <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>
}
35 changes: 35 additions & 0 deletions examples/react-19/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"target": "ES2017"
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
Loading
Loading