Skip to content

Commit

Permalink
fix(Leva): disable dev warning (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 28, 2022
1 parent 816d15c commit 01eb144
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-walls-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'leva': patch
---

fix(Leva): disable dev warning
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 ReactDOM from 'react-dom'
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)
ReactDOM.render(<Leva isRoot />, rootEl)
render(<Leva isRoot />, rootEl)
}
}
rootInitialized = true
Expand Down
16 changes: 16 additions & 0 deletions packages/leva/src/utils/react.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
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

1 comment on commit 01eb144

@vercel
Copy link

@vercel vercel bot commented on 01eb144 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

leva – ./

leva-pmndrs.vercel.app
leva.pmnd.rs
leva.vercel.app
leva-git-main-pmndrs.vercel.app

Please sign in to comment.