Skip to content

Commit 39e9c3b

Browse files
authored
fix: fix applying the default component for components with numbers
2 parents 059b980 + 8d7bd6e commit 39e9c3b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/runtime/composables/useDrupalCe/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,20 @@ export const useDrupalCe = () => {
257257
}
258258

259259
// Progressively remove segments from the custom element name to find a matching default component.
260-
const regex = /-?[a-z]+$/
260+
const regex = /-?[^-]+$/
261261
let componentName = element
262262
while (componentName) {
263263
// Try resolving by adding 'Default' suffix.
264264
const fallbackComponent = nuxtApp.vueApp.component(formatName(componentName) + 'Default')
265265
if (typeof fallbackComponent === 'object' && fallbackComponent.name) {
266266
return fallbackComponent
267267
}
268-
componentName = componentName.replace(regex, '')
268+
let newComponentName = componentName.replace(regex, '')
269+
if (newComponentName === componentName) {
270+
// No more segments to remove, break the loop.
271+
break
272+
}
273+
componentName = newComponentName
269274
}
270275

271276
// If not found, try with resolveComponent. This provides a warning if the component is not found.

test/unit/renderCustomElements-defaults.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ describe('Custom Element Fallback Tests', () => {
5656
expect(wrapper.findComponent(NodeArticleDefault).exists()).toBe(true)
5757
})
5858

59+
it('falls back to node-article--default when component name contains special characters', async () => {
60+
const elementData = {
61+
element: 'node-article-v2$넌😯',
62+
content: 'Testing intermediate fallback with special characters'
63+
}
64+
const wrapper = await mountSuspended(createTestComponent(elementData))
65+
expect(wrapper.html()).toContain('Testing intermediate fallback with special characters')
66+
expect(wrapper.findComponent(NodeArticleDefault).exists()).toBe(true)
67+
})
68+
5969
it('falls back to node--default when no intermediate default found', async () => {
6070
const elementData = {
6171
element: 'node-special-custom',

0 commit comments

Comments
 (0)