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
{{ message }}
Repository navigation
Broken value-object toString interpolation in v6 #5740
Plain Objects with a custom own toString() method are not interpolated correctly in tagged template literals. Instead of calling toString(), styled-components treats them as CSS-in-JS styled objects via the isPlainObject check in flatten(), producing broken CSS output.
I noticed this was previously reported in issue 4312 but was closed as stale.
Why I'm hitting this issue
I'm building a design token system where token groups carry sub-values as properties (e.g. default, hovered, pressed). I've defined toString() to resolve to the default value so consumers can write theme.color.text instead of needing to write the full theme.color.text.default.
Expected behavior: toString() gets called on the value object and returns color: #000000 in the example.
Current behavior: isPlainObject returns true, so flatten() routes the object into objToCssArrayInto, which iterates every key (default, subtle, toString) and emits them as CSS property-value pairs.
Cause
I've been exploring flatten.ts, it seems like the isPlainObject checruns before the toString() fallback. Since object literals have constructor.name === 'Object' they are always caught by isPlainObject and never reach the final branch that calls .toString()
Fix: Could this be fixed by checking for a custom toString before checking isPlainObject with hasOwnProperty('toString')?
Activity
test(v7): cross-cutting integration suite updates
test(v7): cross-cutting integration suite updates
quantizor commentedon May 14, 2026
Could you try
[email protected]when you get a chance?quantizor commentedon May 19, 2026
Fix released with 6.4.2