Repository navigation
Description
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
Steps to reproduce
- Make a value-object with
toStringmethod defined (line 18).toStringshould 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.
Activity
quantizor commentedon Mar 19, 2026
Closing — stale with no engagement. If value-object
toString()interpolation is still broken on v6.3.x, please open a new issue with a reproduction.