Skip to content

V6 breaks value-object toString stylesheet interpolation #4312

Closed as not planned

Description

@drizzer14

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.

Activity

  1. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions