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!: React 18 and 19 support #511

Merged
merged 6 commits into from
Jan 22, 2025
Merged
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
9 changes: 9 additions & 0 deletions .changeset/unlucky-books-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'leva': minor
'@leva-ui/plugin-bezier': minor
'@leva-ui/plugin-dates': minor
'@leva-ui/plugin-plot': minor
'@leva-ui/plugin-spring': minor
---

feat!: React 18 and 19 support
8 changes: 4 additions & 4 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"@stitches/react": "1.2.8",
"leva": "*",
"noisejs": "^2.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-use": "^17.3.2",
"three": "^0.143.0",
"wouter": "^2.7.5"
},
"devDependencies": {
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react-refresh": "^1.3.6",
"typescript": "^4.5.5",
"vite": "2.7.13"
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-advanced-panels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"main": "src/index.jsx",
"dependencies": {
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-busy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"@radix-ui/react-icons": "^1.0.2",
"leva": "*",
"noisejs": "2.1.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3",
"react-use": "^17.2.4"
},
Expand All @@ -24,8 +24,8 @@
"not op_mini all"
],
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
}
}
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-custom-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"main": "src/index.tsx",
"dependencies": {
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"dependencies": {
"@radix-ui/react-icons": "^1.0.2",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-plugin-bezier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"dependencies": {
"@leva-ui/plugin-bezier": "*",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-plugin-dates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"dependencies": {
"@leva-ui/plugin-dates": "*",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-plugin-plot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"dependencies": {
"@leva-ui/plugin-plot": "*",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/sandboxes/leva-plugin-spring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"dependencies": {
"@leva-ui/plugin-spring": "*",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"typescript": "^4.1.5"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dependencies": {
"leva": "*",
"noisejs": "2.1.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"leva": "*",
"@leva-ui/plugin-spring": "*",
"noisejs": "2.1.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-transient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"@react-three/drei": "^4.3.3",
"@react-three/fiber": "^6.0.21",
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "4.0.3",
"three": "^0.143.0"
},
Expand Down
4 changes: 2 additions & 2 deletions demo/src/sandboxes/leva-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"main": "src/index.jsx",
"dependencies": {
"leva": "*",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-dropzone": "11.3.1",
"react-scripts": "4.0.3",
"react-use-gesture": "^9.0.0"
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
},
"bugs": "https://github.com/pmndrs/leva/issues",
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"devDependencies": {
"@babel/core": "^7.17.0",
Expand All @@ -70,15 +70,15 @@
"@emotion/react": "^11.7.1",
"@preconstruct/cli": "^2.1.5",
"@radix-ui/react-icons": "^1.0.3",
"@size-limit/preset-big-lib": "^8.1.0",
"@size-limit/preset-big-lib": "^11.0.0",
"@storybook/addon-actions": "^6.4.18",
"@storybook/addon-essentials": "^6.4.18",
"@storybook/addon-links": "^6.4.18",
"@storybook/addon-storysource": "^6.4.18",
"@storybook/react": "^6.4.18",
"@testing-library/cypress": "^8.0.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"all-contributors-cli": "^6.20.0",
Expand All @@ -97,8 +97,8 @@
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"size-limit": "^8.1.0",
"start-server-and-test": "^1.14.0",
"tsd": "^0.19.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/leva/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
]
},
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"dependencies": {
"@radix-ui/react-portal": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/leva/src/components/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ButtonGroupInputOpts, ButtonGroupOpts } from '../../types'
import { useStoreContext } from '../..'

export type ButtonGroupInternalOpts = {
label: null | JSX.Element | string
label: null | React.JSX.Element | string
opts: ButtonGroupInputOpts
}

Expand Down
4 changes: 2 additions & 2 deletions packages/leva/src/components/Leva/Leva.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react'
import { createRoot } from 'react-dom/client'
import { levaStore } from '../../store'
import { LevaRoot, LevaRootProps } from './LevaRoot'
import { render } from '../../utils/react'

let rootInitialized = false
let rootEl: HTMLElement | null = null
Expand Down Expand Up @@ -40,7 +40,7 @@ export function useRenderRoot(isGlobalPanel: boolean) {
document.getElementById('leva__root') || Object.assign(document.createElement('div'), { id: 'leva__root' })
if (document.body) {
document.body.appendChild(rootEl)
render(<Leva isRoot />, rootEl)
createRoot(rootEl).render(<Leva isRoot />)
}
}
rootInitialized = true
Expand Down
4 changes: 3 additions & 1 deletion packages/leva/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export function usePanelSettingsContext() {
return useContext(PanelSettingsContext)!
}

type ReactChild = React.ReactElement | string | number

type LevaStoreProviderProps = {
children: React.ReactChild | React.ReactChild[] | React.ReactChildren
children: ReactChild | ReactChild[] | typeof React.Children
store: StoreType
}

Expand Down
2 changes: 1 addition & 1 deletion packages/leva/src/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type StoreType = {

export type CommonOptions = {
key: string
label: string | JSX.Element
label: string | React.JSX.Element
hint?: string
render?: RenderFn
order: number
Expand Down
6 changes: 3 additions & 3 deletions packages/leva/src/types/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type ButtonGroupOpts = {
export type ButtonGroupInputOpts =
| ButtonGroupOpts
| {
label?: string | JSX.Element | null
label?: string | React.JSX.Element | null
opts: ButtonGroupOpts
}

Expand Down Expand Up @@ -143,7 +143,7 @@ type SchemaItem =

type GenericSchemaItemOptions = {
render?: RenderFn
label?: string | JSX.Element
label?: string | React.JSX.Element
hint?: string
order?: number
}
Expand Down Expand Up @@ -321,7 +321,7 @@ export interface Plugin<Input, Value = Input, InternalSettings = {}> {

export type InputContextProps = {
id: string
label: string | JSX.Element
label: string | React.JSX.Element
hint?: string
path: string
key: string
Expand Down
16 changes: 0 additions & 16 deletions packages/leva/src/utils/react.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
import React from 'react'
import ReactDOM from 'react-dom'

/**
* With React 18, renderers will warn when not using the new createRoot signature to opt-in to concurrent mode.
* We're okay with creating a (blocking) legacy root to support older versions, so we disable the warning.
* @see https://github.com/facebook/react/pull/21652
*/
export function render<P>(element: React.ReactElement<P>, container: HTMLElement): void {
// eslint-disable-next-line no-console
const error = console.error
// eslint-disable-next-line no-console
console.error = () => {}
ReactDOM.render(element, container)
// eslint-disable-next-line no-console
console.error = error
}

/*
* https://github.com/gregberge/react-merge-refs
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-bezier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"bugs": "https://github.com/pmndrs/leva/issues",
"peerDependencies": {
"leva": ">=0.9.23",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
"leva": ">=0.10.0",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"dependencies": {
"react-use-measure": "^2.1.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-dates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"bugs": "https://github.com/pmndrs/leva/issues",
"peerDependencies": {
"@use-gesture/react": "^10.0.0",
"leva": ">=0.9.34",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
"leva": ">=0.10.0",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"dependencies": {
"react-datepicker": "^4.8.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-plot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"bugs": "https://github.com/pmndrs/leva/issues",
"peerDependencies": {
"@use-gesture/react": "^10.0.0",
"leva": ">=0.9.15",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
"leva": ">=0.10.0",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
},
"dependencies": {
"mathjs": "^10.1.1"
Expand Down
Loading