fix(hmr): handle possible duplicate component definitions with same id

fixes regression in vitepress
This commit is contained in:
Evan You
2021-09-08 18:36:21 -04:00
parent 96b531bfa3
commit aa8908a854
2 changed files with 65 additions and 69 deletions

View File

@@ -36,9 +36,9 @@ describe('hot module replacement', () => {
})
test('createRecord', () => {
expect(createRecord('test1', {})).toBe(true)
expect(createRecord('test1')).toBe(true)
// if id has already been created, should return false
expect(createRecord('test1', {})).toBe(false)
expect(createRecord('test1')).toBe(false)
})
test('rerender', async () => {
@@ -50,7 +50,7 @@ describe('hot module replacement', () => {
__hmrId: childId,
render: compileToFunction(`<div><slot/></div>`)
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
__hmrId: parentId,
@@ -62,7 +62,7 @@ describe('hot module replacement', () => {
`<div @click="count++">{{ count }}<Child>{{ count }}</Child></div>`
)
}
createRecord(parentId, Parent)
createRecord(parentId)
render(h(Parent), root)
expect(serializeInner(root)).toBe(`<div>0<div>0</div></div>`)
@@ -128,7 +128,7 @@ describe('hot module replacement', () => {
unmounted: unmountSpy,
render: compileToFunction(`<div @click="count++">{{ count }}</div>`)
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
render: () => h(Child)
@@ -167,7 +167,7 @@ describe('hot module replacement', () => {
render: compileToFunction(`<div @click="count++">{{ count }}</div>`)
}
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
render: () => h(Child)
@@ -212,7 +212,7 @@ describe('hot module replacement', () => {
},
render: compileToFunction(template)
}
createRecord(id, Comp)
createRecord(id)
render(h(Comp), root)
expect(serializeInner(root)).toBe(
@@ -249,14 +249,14 @@ describe('hot module replacement', () => {
},
render: compileToFunction(`<div>{{ msg }}</div>`)
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
__hmrId: parentId,
components: { Child },
render: compileToFunction(`<Child msg="foo" />`)
}
createRecord(parentId, Parent)
createRecord(parentId)
render(h(Parent), root)
expect(serializeInner(root)).toBe(`<div>foo</div>`)
@@ -275,14 +275,14 @@ describe('hot module replacement', () => {
__hmrId: childId,
render: compileToFunction(`<div>child</div>`)
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
__hmrId: parentId,
components: { Child },
render: compileToFunction(`<Child class="test" />`)
}
createRecord(parentId, Parent)
createRecord(parentId)
render(h(Parent), root)
expect(serializeInner(root)).toBe(`<div class="test">child</div>`)
@@ -302,7 +302,7 @@ describe('hot module replacement', () => {
__hmrId: childId,
render: compileToFunction(`<div>child</div>`)
}
createRecord(childId, Child)
createRecord(childId)
const components: ComponentOptions[] = []
@@ -324,7 +324,7 @@ describe('hot module replacement', () => {
}
}
createRecord(parentId, parentComp)
createRecord(parentId)
}
const last = components[components.length - 1]
@@ -370,7 +370,7 @@ describe('hot module replacement', () => {
</Child>
`)
}
createRecord(parentId, Parent)
createRecord(parentId)
render(h(Parent), root)
expect(serializeInner(root)).toBe(
@@ -410,7 +410,7 @@ describe('hot module replacement', () => {
return h('div')
}
}
createRecord(childId, Child)
createRecord(childId)
const Parent: ComponentOptions = {
render: () => h(Child)