leva icon indicating copy to clipboard operation
leva copied to clipboard

Leva 0.9.35 color picker error : Cannot read properties of null (reading 'getBoundingClientRect')

Open Sean-Bradley opened this issue 1 year ago • 12 comments

When pressing the color picker coloured square, a JS error occurs. ([email protected])

In Chrome and Edge, the error is,

react-dom.development.js:22878  Uncaught TypeError: Cannot read properties of null (reading 'getBoundingClientRect')
    at leva.esm.js:137:30
    at commitHookEffectListMount (react-dom.development.js:23189:26)
    at commitLayoutEffectOnFiber (react-dom.development.js:23307:17)
    at commitLayoutMountEffects_complete (react-dom.development.js:24727:9)
    at commitLayoutEffects_begin (react-dom.development.js:24713:7)
    at commitLayoutEffects (react-dom.development.js:24651:3)
    at commitRootImpl (react-dom.development.js:26862:5)
    at commitRoot (react-dom.development.js:26721:5)
    at performSyncWorkOnRoot (react-dom.development.js:26156:3)
    at flushSyncCallbacks (react-dom.development.js:12042:22)

In FireFox, the error is written differently,

Uncaught TypeError: wrapperRef.current is null
    usePopin leva.esm.js:137
    React 24
    render vector-plugin-6f82aee9.esm.js:466
    useRenderRoot leva.esm.js:2172
    React 8
    workLoop scheduler.development.js:266
    flushWork scheduler.development.js:239
    performWorkUntilDeadline scheduler.development.js:533
    js scheduler.development.js:571
    js scheduler.development.js:633
    __require chunk-I4MZPW7S.js:8
    js index.js:6
    __require chunk-I4MZPW7S.js:8
    React 2
    __require chunk-I4MZPW7S.js:8
    js React
    __require chunk-I4MZPW7S.js:8
    js React
    __require chunk-I4MZPW7S.js:8
    <anonymous> react-dom_client.js:37

The error does not happen with [email protected], but does occur in [email protected]

E.g., This is a minimal example. Press the green square in the Leva panel and view the browser console.

https://k6m8gm-5173.csb.app/

react 18.3.1 react-dom 18.3.1 leva 0.9.35

I have also tried react 18.2.0 and the error still occurs.

This error occurs when using a bundler locally. I have tried Vite, React-Scripts, R3F-Pack and WebPack.

The error also occurs when using the newer CodeSandbox DevBox IDE, but not the legacy Sandbox IDE.

This CodeSandbox DevBox link below demonstrates the problem, it is a Vite project.

https://codesandbox.io/p/devbox/leva-color-picker-k6m8gm?file=%2Fsrc%2Findex.jsx

And here is a zip of the mini Vite project. sandbox.zip

unzip it, cd into folder,

npm install
npm run dev 

Open http://localhost:5173/

And this is the minimal script.

import React from 'react'
import { createRoot } from 'react-dom/client'
import { useControls } from 'leva'

function App() {
    const color = useControls({
        value: 'lime'
    })

    return (
        <div style={{ backgroundColor: color.value }}>
            <h1>Hello, world!</h1>
            <h2>Time is {new Date().toLocaleTimeString('en-US')}.</h2>
        </div>
    )
}

createRoot(document.getElementById('root')).render(<App />)

Sean-Bradley avatar Jul 05 '24 16:07 Sean-Bradley

Same problem here.

Jbmanllr avatar Jul 07 '24 13:07 Jbmanllr

Also encountering this issue

Kalekdan avatar Jul 15 '24 13:07 Kalekdan

It is specifically this line in the usePopin function for me.

const {
  height
} = wrapperRef.current.getBoundingClientRect();

Kreshnik avatar Jul 16 '24 22:07 Kreshnik

Same :(

l4j3b avatar Jul 17 '24 01:07 l4j3b

same

laileihuang avatar Jul 18 '24 07:07 laileihuang

same here

ericrius1 avatar Jul 18 '24 08:07 ericrius1

Here is a band-aid until there is a fix.

Add an overrides to your package.json to lower the @radix-ui/react-portal version which Leva imports as a dependency.

  "overrides": {
    "leva": {
      "@radix-ui/react-portal": "1.0.2"
    }
  }

Run,

npm install

# vite
npm run dev

# react-scripts | r3f-pack
npm start 

Sean-Bradley avatar Jul 19 '24 15:07 Sean-Bradley

Here is a band-aid until there is a fix.

Add an overrides to your package.json to lower the @radix-ui/react-portal version which Leva imports as a dependency.

  "overrides": {
    "leva": {
      "@radix-ui/react-portal": "1.0.2"
    }
  }

Run,

npm install

npm run dev

Thanks !

PNPM version:

"pnpm": { "overrides": { "_comment": "Temporary fix for leva control color selection. See: https://github.com/pmndrs/leva/issues/508#issuecomment-2228569482", "leva>@radix-ui/react-portal": "1.0.2" } },

Jbmanllr avatar Jul 20 '24 15:07 Jbmanllr

It's working with previous version: 0.9.34

Mdelacruzmelo avatar Aug 21 '24 21:08 Mdelacruzmelo

Im on 0.9.35 and have this issue, but the band-aid solution works

MagnesiumDev avatar Aug 24 '24 16:08 MagnesiumDev

it work! "overrides": { "leva": { "@radix-ui/react-portal": "1.0.2" } }

golden-fruit avatar Sep 05 '24 06:09 golden-fruit

PNPM version:

"pnpm": { "overrides": { "_comment": "Temporary fix for leva control color selection. See: https://github.com/pmndrs/leva/issues/508#issuecomment-2228569482", "leva>@radix-ui/react-portal": "1.0.2" } },

Out of curiosity, how did you get the _comment to work, though? I get:

ERR_PNPM_INVALID_SELECTOR Cannot parse the "_comment" selector

mz8i avatar Sep 15 '24 11:09 mz8i

If you are using yarn

"resolutions": {
    "@radix-ui/react-portal": "1.0.2"
}

and then run: yarn

niccolofanton avatar Oct 24 '24 16:10 niccolofanton

Band aid still works. Thanks @Sean-Bradley

Tom-Sloan avatar Oct 28 '24 22:10 Tom-Sloan

When official update?

izmaelmag avatar Nov 15 '24 17:11 izmaelmag

Same here guys ;)

ektogamat avatar Nov 17 '24 20:11 ektogamat

If you are using yarn如果您使用的是纱线

"resolutions": {
    "@radix-ui/react-portal": "1.0.2"
}

and then run: yarn然后运行: yarn

pnpm should do this as well

fanchen4139 avatar Nov 20 '24 06:11 fanchen4139