Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V6 breaks value-object toString stylesheet interpolation #4312

Open
drizzer14 opened this issue May 17, 2024 · 0 comments
Open

V6 breaks value-object toString stylesheet interpolation #4312

drizzer14 opened this issue May 17, 2024 · 0 comments

Comments

@drizzer14
Copy link

drizzer14 commented May 17, 2024

Environment

System:

  • OS: macOS 14.3.1
  • CPU: (10) arm64 Apple M1 Pro
  • Memory: 106.25 MB / 16.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
  • Yarn: 1.22.19 - ~/.yarn/bin/yarn
  • npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  • Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman

npmPackages:

  • babel-plugin-styled-components: 2.1.4 => 2.1.4
  • styled-components: 6.1.10 => 6.1.10

Reproduction

https://codesandbox.io/p/devbox/sc6-react18-object-interpolation-g6x5gf

Steps to reproduce

  1. 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).
  2. 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:

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant