Skip to content

Commit

Permalink
Switches to createRoot, increases React minimum to v18 to support v19
Browse files Browse the repository at this point in the history
  • Loading branch information
lourd committed Aug 17, 2024
1 parent b333a28 commit 89db3d4
Show file tree
Hide file tree
Showing 18 changed files with 1,175 additions and 260 deletions.
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",
"react-dom": ">=18.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",
"react-dom": ">=18.0.0"
},
"dependencies": {
"@radix-ui/react-portal": "^1.0.2",
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
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
Loading

0 comments on commit 89db3d4

Please sign in to comment.