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
Make a value-object with toString method defined (line 18). toString should return any valid CSS value (CSS custom property reference in my case) (line 15).
Interpolate created object into a template string stylesheet of a styled component (line 21).
Expected Behavior
In styled-components v5 this interpolation would result in toString method being called on a value-object as it should happen in plain JavaScript. Resulting stylesheet would include the value returned by toString, e.g. color: ${cssVar}; -> color: var(--css-var); After upgrading to v6, I expected the same behaviour to persist, since I'm using value-objects like these to build a design system library.
Actual Behavior
v6 interpolation results in whole object getting interpolated into the stylesheet which looks like defined toString is ignored completely:
This behaviour can be observed in the attached reproduction using browser inspector (not the internal CodeSandbox one – it just filters-out invalid CSS).
Reproduction includes close to the real world code that I've been using in my design system library both before and after migration to styled-components v6. I haven't found any mentions of changes even remotely related to something that could cause this behaviour, that's why I'm considering this to be a bug.
Additionally, I've found a half-workaround for this issue – if the interpolated value-object is created via class instantiation instead of an object literal, the interpolation works as expected (as in v5 prior to this major update). However, this method causes another issue which I've opened as a separate bug report, since to my mind it's not necessarily related to this one producing a different result and another error.
The text was updated successfully, but these errors were encountered:
Environment
System:
Binaries:
npmPackages:
Reproduction
https://codesandbox.io/p/devbox/sc6-react18-object-interpolation-g6x5gf
Steps to reproduce
toString
method defined (line 18).toString
should return any valid CSS value (CSS custom property reference in my case) (line 15).Expected Behavior
In
styled-components
v5 this interpolation would result intoString
method being called on a value-object as it should happen in plain JavaScript. Resulting stylesheet would include the value returned bytoString
, e.g.color: ${cssVar};
->color: var(--css-var);
After upgrading to v6, I expected the same behaviour to persist, since I'm using value-objects like these to build a design system library.Actual Behavior
v6 interpolation results in whole object getting interpolated into the stylesheet which looks like defined
toString
is ignored completely:This behaviour can be observed in the attached reproduction using browser inspector (not the internal CodeSandbox one – it just filters-out invalid CSS).
Reproduction includes close to the real world code that I've been using in my design system library both before and after migration to
styled-components
v6. I haven't found any mentions of changes even remotely related to something that could cause this behaviour, that's why I'm considering this to be a bug.Additionally, I've found a half-workaround for this issue – if the interpolated value-object is created via class instantiation instead of an object literal, the interpolation works as expected (as in v5 prior to this major update). However, this method causes another issue which I've opened as a separate bug report, since to my mind it's not necessarily related to this one producing a different result and another error.
The text was updated successfully, but these errors were encountered: