Skip to content

Commit 2afa260

Browse files
committed
ensure local assets is prioritized regardless of naming convention (fix vuejs#4434)
1 parent 6cfd6c7 commit 2afa260

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/core/util/options.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,14 @@ export function resolveAsset (
319319
return
320320
}
321321
const assets = options[type]
322-
const res = assets[id] ||
323-
// camelCase ID
324-
assets[camelize(id)] ||
325-
// Pascal Case ID
326-
assets[capitalize(camelize(id))]
322+
// check local registration variations first
323+
if (hasOwn(assets, id)) return assets[id]
324+
const camelizedId = camelize(id)
325+
if (hasOwn(assets, camelizedId)) return assets[camelizedId]
326+
const PascalCaseId = capitalize(camelizedId)
327+
if (hasOwn(assets, PascalCaseId)) return assets[PascalCaseId]
328+
// fallback to prototype chain
329+
const res = assets[id] || assets[camelizedId] || assets[PascalCaseId]
327330
if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
328331
warn(
329332
'Failed to resolve ' + type.slice(0, -1) + ': ' + id,

test/unit/features/global-api/assets.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ describe('Global API: assets', () => {
4848
// extended registration should not pollute global
4949
expect(Vue.options.components.test).toBeUndefined()
5050
})
51+
52+
// #4434
53+
it('local registration should take priority regardless of naming convention', () => {
54+
Vue.component('x-foo', {
55+
template: '<span>global</span>'
56+
})
57+
const vm = new Vue({
58+
components: {
59+
xFoo: {
60+
template: '<span>local</span>'
61+
}
62+
},
63+
template: '<div><x-foo></x-foo></div>'
64+
}).$mount()
65+
expect(vm.$el.textContent).toBe('local')
66+
delete Vue.options.components['x-foo']
67+
})
5168
})

0 commit comments

Comments
 (0)