Skip to content

Commit

Permalink
fix(core): static trees should be cached on options (#6826) (#6837)
Browse files Browse the repository at this point in the history
* test(once): failing test for #6826

* fix(core): static trees should be cached on options (#6826)
  • Loading branch information
jkzing authored and yyx990803 committed Oct 18, 2017
1 parent 9caed00 commit b6c384d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/instance/render-helpers/render-static.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b6c384d

Please sign in to comment.