Repository navigation
Conversation
createStylisInstance called the error helper for an unnamed plugin without throwing its result, so anonymous plugins were accepted silently and shared class names with plugin-less renders. Refs styled-components#5828
🦋 Changeset detectedLatest commit: e545904 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
ℹ️ No critical issues — two minor notes inline, plus one release-strategy question below.
Reviewed changes
- Throw error #15 for unnamed plugins —
createStylisInstancenow throws the value returned by the error factory instead of discarding it, so an unnamed or anonymous plugin is rejected as documented.packages/styled-components/src/utils/stylis.ts:367 - Regression coverage — the unnamed-plugin test now asserts the #15 message and a new test covers an anonymous arrow function, the case previously accepted silently.
packages/styled-components/src/models/test/StyleSheetManager.test.tsx:360 - Patch changeset —
.changeset/throw-unnamed-plugin-error.md.
ℹ️ A hard throw now ships in a 6.x patch
The fix restores the documented contract and matches main's v7 compiler.ts (if (!name) throw throwStyledError(15)), so the behavior is correct. The open question is release mechanics rather than code: apps on 6.x that pass an anonymous plugin work today (with the silent class-name collision) and will start throwing at component creation after a patch upgrade. That is the trade-off the description already flags; the call between a hard throw and a dev-only warning belongs to the maintainers.
Technical details
# Release tier when previously-accepted input becomes a throw
## Affected sites
- `.changeset/throw-unnamed-plugin-error.md:2` — declares `patch`.
- `packages/styled-components/src/utils/stylis.ts:367` — throws error 15 during `createStylisInstance`, i.e. at `StyleSheetManager` render / first styled component that carries plugins.
## Required outcome
- Confirm whether restoring the documented throw (now identical to main) is acceptable on a 6.x patch, or whether 6.x should warn in development and defer the hard throw to 7.x.
## Open questions for the human
- Is there precedent on 6.x for promoting previously-silent input to a hard error in a patch release?deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| "styled-components": patch | ||
| --- | ||
|
|
||
| A stylis plugin without a name passed to `<StyleSheetManager stylisPlugins={[...]}>` now throws the documented "not named" error (#15) again. The error was being created but never thrown, so an anonymous function was accepted silently and shared its class names with the same component rendered without plugins. |
There was a problem hiding this comment.
The changeset rules ask for what a user observes, without mechanism descriptions, and "The error was being created but never thrown" is an internal detail the reader hasn't seen. Consider keeping only the observable half — an anonymous plugin was previously accepted silently (and could share class names with the same component rendered without plugins) and now throws error #15.
| </StyleSheetManager> | ||
| ) | ||
| ).toThrow(); | ||
| ).toThrow(/A stylis plugin has been supplied that is not named/); |
There was a problem hiding this comment.
This assertion now genuinely exercises the throw path, which exposes a fragility: stylisRTLPlugin.name is restored only on the following line, so whenever the assertion fails the restore is skipped and later tests in the file fail too (reverting only stylis.ts:367 cascaded into two unrelated failures). Wrapping the mutation and restore in try/finally, or building a one-off plugin instead of mutating the shared one, keeps a regression localized to this test.

Fixes the 6.x part of #5828 ("Related on 6.x: a plugin with no name is supposed to throw error 15, but the error is created and never thrown").
Problem
createStylisInstancechecks each plugin's name withbut
utils/erroronly builds and returns theError; every other call site writesthrow styledError(...). So on 6.x an anonymous function passed instylisPluginsis accepted silently, contributes an empty string to the hash, and shares its class names with the same component rendered without plugins.The existing test for this passed by accident: it sets
nametoundefined, which made the next line (phash(h, undefined)) throwCannot read properties of undefined (reading 'length').Change
This does not change the hashing for two different plugins that share a name, the main subject of #5828.
One thing to weigh: apps on 6.x that pass an anonymous plugin today work (with the class-name collision described above) and will start throwing error 15 after this. That is the documented behaviour and what main does, but it lands in a patch release. If you would rather have a development-only warning on 6.x, I can change it.
Testing
test:web(980 tests, 624 snapshots),test:native(45 tests),typecheckandtest:typespass locally (Linux, Node 24).