Warn in dev on duplicate component registration#736
Merged
Conversation
…onent `addToRegistry` is first-writer-wins by design — a name maps to a single component, mirroring `customElements.define` (for future interop). It silently ignored a second registration under an existing name, dropping a same-name subclass's declared children from the global auto-mount registry with no signal. Keep the register-once semantics; emit a dev-mode warning on a different-ctor collision, steering to a unique `config.name` or `withExtraConfig`. Co-authored-by: Claude
Co-authored-by: Claude
Export Size@studiometa/js-toolkit
Unchanged@studiometa/js-toolkit
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #736 +/- ##
=======================================
Coverage 97.45% 97.45%
=======================================
Files 162 162
Lines 3735 3737 +2
Branches 1043 1044 +1
=======================================
+ Hits 3640 3642 +2
Misses 85 85
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
addToRegistryis intentionally first-writer-wins — a name maps to a single component, mirroringcustomElements.define(in anticipation of future Custom Elements interop;el.__base__is likewise keyed byconfig.name, so two same-name components can't coexist). But a second registration under an existing name was silently ignored, so a same-config.namesubclass addingconfig.componentshad its declared children dropped from the global auto-mount registry with no signal — dynamically-injected children then never auto-mounted.Rather than change the register-once semantics (which would diverge from the Custom Elements model), this makes the collision loud in development, like
customElements.definethrowing on a duplicate name:console.warnwhenaddToRegistryis called with a name already mapped to a different constructor, steering to a uniqueconfig.nameorwithExtraConfig(which auto-renames).utils.spec.ts"should not override an existing component" are preserved.Added a test asserting the warn fires on a different-ctor collision and not on same-class re-registration. Full suite green (930 passed);
oxlint/tsgo/prettier clean.🤖 Generated with Claude Code