Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): static trees should be cached on options (#6826) #6837

Merged
merged 2 commits into from Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/instance/render-helpers/render-static.js
Expand Up @@ -11,8 +11,8 @@ export function renderStatic (
): VNode | Array<VNode> {
// static trees can be rendered once and cached on the contructor options
// so every instance shares the same cached trees
const renderFns = this.$options.staticRenderFns
const cached = renderFns.cached || (renderFns.cached = [])
const options = this.$options
const cached = options.cached || (options.cached = [])
let tree = cached[index]
// if has already-rendered static tree and not inside v-for,
// we can reuse the same tree by doing a shallow clone.
Expand All @@ -22,7 +22,7 @@ export function renderStatic (
: cloneVNode(tree)
}
// otherwise, render a fresh tree.
tree = cached[index] = renderFns[index].call(this._renderProxy, null, this)
tree = cached[index] = options.staticRenderFns[index].call(this._renderProxy, null, this)
markStatic(tree, `__static__${index}`, false)
return tree
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/features/directives/once.spec.js
Expand Up @@ -335,6 +335,28 @@ describe('Directive v-once', () => {
vm.ok = false // teardown component with v-once
}).then(done) // should not throw
})

// #6826
it('should render different component instances properly', done => {
const vm = new Vue({
components: {
foo: {
props: ['name'],
template: '<div v-once>{{ name }}</div>'
}
},
template: `
<div>
<foo name="a" v-once></foo>
<foo name="b" v-once></foo>
</div>
`
}).$mount()
waitForUpdate(() => {
expect(vm.$el.children[0].innerHTML).toBe('a')
expect(vm.$el.children[1].innerHTML).toBe('b')
}).then(done)
})
})

function expectTextContent (vm, text) {
Expand Down