Skip to content

Commit f31af0d

Browse files
Copilothotlong
andcommitted
Fix Registry namespace lookup and PluginSystem tests
- Add deprecation warning when registering components without namespace - Fix Registry.get() to not fallback when namespace is explicitly provided - Fix Registry.has() to not fallback when namespace is explicitly provided - Fix Registry.getConfig() to not fallback when namespace is explicitly provided - Fix PluginSystem tests to use legacy mode (useScope: false) for direct registry access - All 91 tests now passing Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 3f1fac4 commit f31af0d

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

packages/core/src/registry/Registry.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ export class Registry<T = any> {
7272
register(type: string, component: ComponentRenderer<T>, meta?: ComponentMeta) {
7373
const fullType = meta?.namespace ? `${meta.namespace}:${type}` : type;
7474

75+
// Warn if registering without namespace (deprecated pattern)
76+
if (!meta?.namespace) {
77+
console.warn(
78+
`Registering component "${type}" without a namespace is deprecated. ` +
79+
`Please provide a namespace in the meta parameter.`
80+
);
81+
}
82+
7583
if (this.components.has(fullType)) {
7684
// console.warn(`Component type "${fullType}" is already registered. Overwriting.`);
7785
}
@@ -84,7 +92,7 @@ export class Registry<T = any> {
8492

8593
// Also register without namespace for backward compatibility
8694
// This allows "button" to work even when registered as "ui:button"
87-
if (meta?.namespace && !this.components.has(type)) {
95+
if (meta?.namespace) {
8896
this.components.set(type, {
8997
type: fullType, // Keep reference to namespaced type
9098
component,
@@ -113,16 +121,13 @@ export class Registry<T = any> {
113121
* registry.get('button', 'ui') // Tries 'ui:button' first, then 'button'
114122
*/
115123
get(type: string, namespace?: string): ComponentRenderer<T> | undefined {
116-
// Try namespaced lookup first if namespace provided
124+
// If namespace is explicitly provided, ONLY look in that namespace (no fallback)
117125
if (namespace) {
118126
const namespacedType = `${namespace}:${type}`;
119-
const namespacedComponent = this.components.get(namespacedType);
120-
if (namespacedComponent) {
121-
return namespacedComponent.component;
122-
}
127+
return this.components.get(namespacedType)?.component;
123128
}
124129

125-
// Fallback to direct type lookup
130+
// When no namespace provided, use backward compatibility lookup
126131
return this.components.get(type)?.component;
127132
}
128133

@@ -134,16 +139,13 @@ export class Registry<T = any> {
134139
* @returns Component configuration or undefined
135140
*/
136141
getConfig(type: string, namespace?: string): ComponentConfig<T> | undefined {
137-
// Try namespaced lookup first if namespace provided
142+
// If namespace is explicitly provided, ONLY look in that namespace (no fallback)
138143
if (namespace) {
139144
const namespacedType = `${namespace}:${type}`;
140-
const namespacedConfig = this.components.get(namespacedType);
141-
if (namespacedConfig) {
142-
return namespacedConfig;
143-
}
145+
return this.components.get(namespacedType);
144146
}
145147

146-
// Fallback to direct type lookup
148+
// When no namespace provided, use backward compatibility lookup
147149
return this.components.get(type);
148150
}
149151

@@ -155,12 +157,12 @@ export class Registry<T = any> {
155157
* @returns True if component is registered
156158
*/
157159
has(type: string, namespace?: string): boolean {
160+
// If namespace is explicitly provided, ONLY look in that namespace (no fallback)
158161
if (namespace) {
159162
const namespacedType = `${namespace}:${type}`;
160-
if (this.components.has(namespacedType)) {
161-
return true;
162-
}
163+
return this.components.has(namespacedType);
163164
}
165+
// When no namespace provided, use backward compatibility lookup
164166
return this.components.has(type);
165167
}
166168

packages/core/src/registry/__tests__/PluginSystem.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('PluginSystem', () => {
2828
}
2929
};
3030

31-
await pluginSystem.loadPlugin(plugin, registry);
31+
await pluginSystem.loadPlugin(plugin, registry, false);
3232

3333
expect(pluginSystem.isLoaded('test-plugin')).toBe(true);
3434
expect(pluginSystem.getLoadedPlugins()).toContain('test-plugin');
@@ -201,7 +201,7 @@ describe('PluginSystem', () => {
201201
register: registerFn
202202
};
203203

204-
await pluginSystem.loadPlugin(plugin, registry);
204+
await pluginSystem.loadPlugin(plugin, registry, false);
205205

206206
expect(registerFn).toHaveBeenCalledWith(registry);
207207
expect(registerFn).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)