You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
where value.match returns null, and it tries to essentially do (null).map(Number)
The error reported is rather cryptic, especially when it happens in production in minified code:
TypeError: cannot read properties of null (reading 'map')
at [....]
A much better developer experience would be for react-spring to throw an error, similar to what it does a little further below in the createStringInterpolator code when it checks the arity of values.
To Reproduce
The obvious fix is for the consumer to ensure the CSS variables are defined 😄 .
However, under certain circumstances and despite the developer's best intentions, this can occur. It happened to me on a non-trivial Next.js app that used Emotion's <Global> component to define CSS variables on :root. When performing a client-side route change from a page with a react-spring animation to another page (causing the Global component to unmount) and then navigating back. The Next.js application is non-trivial and I have had difficulty reproducing a simple case as it seems multiple factors are at play, such as the time taken to render a page on the client and the server.
Expected Behaviour
Throw a more meaningful error if the return value of variableToRgba is still a CSS variable (explicit).
An alternative could be to default to what CSS defaults to when a variable cannot be resolved on an element's CSS property - instead of an empty string, it defaults to rgba(0, 0, 0, 0) (to reproduce: create an element with a bogus css variable as its background color, then run window.getComputedStyle(element).backgroundColor). This is less explicit, but it would not throw an error.
Link to repo
N/A
The text was updated successfully, but these errors were encountered:
Hi,
I'm currently using @react-spring/web with something like this :
functionMyComponent(){return(<div><ulclassName="[--from-bg:#000] [--to-bg:#fff] md:[--from-bg:#5f5]"></ul>{/* with tailwindcss */}<ulstyle={{"--from-x": "#000"}asCSSProperties}></ul>{/* without tailwindcss */}</div>);}
I just found this issue and I can't do something as above because it seems that the properties must be on the :root.
Hi. I faced the same problem. When I try to use CSS-variables from outside provider (theme provider of ui-kit) I get this kind of error as above.
It seems to me that it shouldn't provide error at all in such a case, it should be just ignored I think))
Which react-spring target are you using?
@react-spring/web
@react-spring/three
@react-spring/native
@react-spring/konva
@react-spring/zdog
What version of react-spring are you using?
9.5.2
What's Wrong?
When a CSS variable is unavailable, the output of this code in the
variableToRgba
function insidevariableToRgba.ts
is an empty string:If
value
is falsy, the initial value (the name of the CSS variable as a string) is returned.In
stringInterpolation.ts
, this value falls through to:where
value.match
returns null, and it tries to essentially do(null).map(Number)
The error reported is rather cryptic, especially when it happens in production in minified code:
A much better developer experience would be for react-spring to throw an error, similar to what it does a little further below in the
createStringInterpolator
code when it checks the arity of values.To Reproduce
The obvious fix is for the consumer to ensure the CSS variables are defined 😄 .
However, under certain circumstances and despite the developer's best intentions, this can occur. It happened to me on a non-trivial Next.js app that used Emotion's
<Global>
component to define CSS variables on:root
. When performing a client-side route change from a page with a react-spring animation to another page (causing theGlobal
component to unmount) and then navigating back. The Next.js application is non-trivial and I have had difficulty reproducing a simple case as it seems multiple factors are at play, such as the time taken to render a page on the client and the server.Expected Behaviour
Throw a more meaningful error if the return value of
variableToRgba
is still a CSS variable (explicit).An alternative could be to default to what CSS defaults to when a variable cannot be resolved on an element's CSS property - instead of an empty string, it defaults to
rgba(0, 0, 0, 0)
(to reproduce: create an element with a bogus css variable as its background color, then runwindow.getComputedStyle(element).backgroundColor
). This is less explicit, but it would not throw an error.Link to repo
N/A
The text was updated successfully, but these errors were encountered: