Repository navigation
fix: warn in development when two plugins share a name - #5844
Conversation
Class names hash only a plugin's name, which has to match on the server and the client, so development builds warn when two different plugins share one.
🦋 Changeset detectedLatest commit: fd82969 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.
ℹ️ One narrow message-accuracy edge case; the implementation is otherwise sound.
Reviewed changes
- Dev-only collision warning in
createCompiler(utils/compiler.ts) — a lazily allocated module-level name→plugin registry callswarnOnce('plugin-name-collision', ...)when a second, different plugin object arrives under a name already seen. The whole path sits behind__DEV__, so production DCEs both the call and the message string. - Test reset wiring (
test-utils/setupTestFramework.ts) —resetSeenPlugins()joinsresetWarnOnce()in the globalbeforeEach, so the process-wide registry does not leak between tests. - Tests + changeset — six cases in
models/test/StyleSheetManager.test.tsx(two managers, one array, warn-once, same-object reuse, differing names, production) plus a patch changeset.
Verified locally: pnpm --filter styled-components test:web -- StyleSheetManager.test compiler.test prefix.test → 169 passed. The per-test reset keeps the repeatedly redefined dual name in compiler.test.ts and the duplicated project-prefixes in prefix.test.tsx from tripping the warning, and the first-party plugin names (rtl, prefix, rsc) are distinct.
The changed compiler.ts call site keeps the same createCompiler seam, so the DOM and RSC paths both get the warning without new imports on the native entry.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Keyed the collision registry on
nameplusnamespace(utils/compiler.ts) —notePluginNamenow buildsname + '\0' + namespacewhen a namespace is present, so same-named plugins under different namespaces no longer warn. This matches the actual collision condition:createCompilerfolds both the plugin names andoptions.namespaceintocompiler.hash(compiler.ts:180,182), andcompiler.hashis the only plugin-derived input to class names (WebStyle.ts:210,Keyframes.ts:58). - JSDoc and changeset updated — the registry comment and
.changeset/plugin-name-collision.mdnow describe the namespace-scoped condition and note that one name under different namespaces produces different classes. - Two new tests (
models/test/StyleSheetManager.test.tsx) — no warning when same-named plugins sit under different namespaces (also asserting both namespaced rules emit), and a warning when they share one.
Verified locally: pnpm --filter styled-components test:web -- StyleSheetManager.test → 26 passed; compiler.test prefix.test → 145 passed. The prior review's single concern (spurious warning across namespaces) is addressed.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Fixes #5828
Why a warning and not a new hash input
The issue lists two ways out: hash something unique per plugin, or warn in development when two different plugins share a name. I went with the warning. The class name has to come out identical on the server and the client, and neither of the other inputs can promise that:
So the hash still uses only each plugin's
name(plusnamespace), and nothing changes for production output.What changed
src/utils/compiler.ts: in__DEV__only,createCompilerrecords the first plugin object seen for each name. When a later, different object arrives with a name already taken, it callswarnOnce(once per name) and says to give each plugin its own name. The map is created lazily inside the dev branch.test-utils/setupTestFramework.ts: clears that registry inbeforeEach, next to the existingresetWarnOnce()..changeset/plugin-name-collision.md: patch changeset describing the warning.One trade-off worth flagging: because the check is identity-based, a plugin that's re-created on every render with the same name also triggers the (single) warning. Hoisting the plugin out of render avoids it, and that's already the better pattern since a new
pluginsarray means a new compiler.Tests
Added
plugins that share a nameinsrc/models/test/StyleSheetManager.test.tsx:pluginsarray holds two plugins with the same name__DEV__is falseThe warning tests failed before the change and pass after it. Full main jest suite passes (1509 tests),
tsc --noEmitandpnpm format:checkare clean, andpnpm buildpasses with bundle size unchanged (15.36kB standalone gzip, 14.23kB webpack gzip). The warning string doesn't appear instyled-components.min.js.