Skip to content

Commit c7ac0d9

Browse files
authored
fix: clear static tree for slots render (#862)
1 parent 85dd3ec commit c7ac0d9

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

Diff for: packages/create-instance/create-slot-vnodes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ function createVNodes (
88
): Array<VNode> {
99
const el = compileToFunctions(`<div>${slotValue}</div>`)
1010
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns
11-
// version < 2.5
12-
if (!vm._renderProxy._staticTrees) {
13-
vm._renderProxy._staticTrees = []
14-
}
11+
const _staticTrees = vm._renderProxy._staticTrees
12+
vm._renderProxy._staticTrees = []
1513
vm._renderProxy.$options.staticRenderFns = el.staticRenderFns
1614
const vnode = el.render.call(vm._renderProxy, vm.$createElement)
1715
vm._renderProxy.$options.staticRenderFns = _staticRenderFns
16+
vm._renderProxy._staticTrees = _staticTrees
1817
return vnode.children
1918
}
2019

Diff for: test/specs/mounting-options/attachToDocument.spec.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { compileToFunctions } from 'vue-template-compiler'
21
import { describeWithShallowAndMount, isRunningJSDOM } from '~resources/utils'
32
import { renderToString } from '@vue/server-test-utils'
43

54
describeWithShallowAndMount('options.attachToDocument', mountingMethod => {
6-
it('returns VueWrapper with attachedToDocument set to true when passed attachToDocument in options', () => {
7-
const compiled = compileToFunctions('<div><input /></div>')
8-
const wrapper = mountingMethod(compiled, { attachToDocument: true })
5+
it('attaches root node to document', () => {
6+
const TestComponent = {
7+
template: '<div class="attached"><input /></div>'
8+
}
9+
const wrapper = mountingMethod(TestComponent, {
10+
attachToDocument: true
11+
})
12+
expect(document.querySelector('.attached')).to.not.equal(null)
913
expect(wrapper.options.attachedToDocument).to.equal(true)
1014
})
1115
})
@@ -16,8 +20,10 @@ describe('options.attachToDocument with renderToString', () => {
1620
if (!isRunningJSDOM) {
1721
return
1822
}
19-
const compiled = compileToFunctions('<div><input /></div>')
20-
const fn = () => renderToString(compiled, { attachToDocument: true })
23+
const TestComponent = {
24+
template: '<div class="attached"><input /></div>'
25+
}
26+
const fn = () => renderToString(TestComponent, { attachToDocument: true })
2127
const message =
2228
'[vue-test-utils]: you cannot use attachToDocument with renderToString'
2329
expect(fn)

Diff for: test/specs/mounting-options/slots.spec.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,25 @@ describeWithMountingMethods('options.slots', mountingMethod => {
223223
}
224224
})
225225

226+
it('mounts component with default and named slots', () => {
227+
const wrapper = mountingMethod(ComponentWithSlots, {
228+
slots: {
229+
default: '<span>hello</span>',
230+
footer: '<p>world</p>'
231+
}
232+
})
233+
const HTML = mountingMethod.name === 'renderToString'
234+
? wrapper
235+
: wrapper.html()
236+
expect(HTML).to.contain('<span>hello</span>')
237+
expect(HTML).to.contain('<p>world</p>')
238+
})
239+
226240
it('mounts component with default and named text slot', () => {
227241
const wrapper = mountingMethod(ComponentWithSlots, {
228242
slots: {
229243
default: 'hello,',
230-
header: 'world'
244+
footer: '<template>world</template>'
231245
}
232246
})
233247
if (mountingMethod.name === 'renderToString') {

Diff for: test/specs/wrapper/destroy.spec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { compileToFunctions } from 'vue-template-compiler'
21
import { describeWithShallowAndMount } from '~resources/utils'
32
import sinon from 'sinon'
43

@@ -25,9 +24,8 @@ describeWithShallowAndMount('destroy', mountingMethod => {
2524
expect(spy.calledOnce).to.equal(true)
2625
})
2726

28-
it.skip('removes element from document.body', () => {
29-
const compiled = compileToFunctions('<div></div>')
30-
const wrapper = mountingMethod(compiled, { attachToDocument: true })
27+
it('removes element from document.body', () => {
28+
const wrapper = mountingMethod({ template: '<div />' }, { attachToDocument: true })
3129
expect(wrapper.vm.$el.parentNode).to.equal(document.body)
3230
wrapper.destroy()
3331
expect(wrapper.vm.$el.parentNode).to.be.null

0 commit comments

Comments
 (0)