From b6c384dd78b56bd247e6a34d5aea0d3903f5b7fd Mon Sep 17 00:00:00 2001 From: JK Date: Wed, 18 Oct 2017 12:26:55 +0800 Subject: [PATCH] fix(core): static trees should be cached on options (#6826) (#6837) * test(once): failing test for #6826 * fix(core): static trees should be cached on options (#6826) --- .../instance/render-helpers/render-static.js | 6 ++--- test/unit/features/directives/once.spec.js | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/core/instance/render-helpers/render-static.js b/src/core/instance/render-helpers/render-static.js index 02f424d234b..1236c94792c 100644 --- a/src/core/instance/render-helpers/render-static.js +++ b/src/core/instance/render-helpers/render-static.js @@ -11,8 +11,8 @@ export function renderStatic ( ): VNode | Array { // 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. @@ -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 } diff --git a/test/unit/features/directives/once.spec.js b/test/unit/features/directives/once.spec.js index cdfdb0144ec..eca8be0a3ef 100644 --- a/test/unit/features/directives/once.spec.js +++ b/test/unit/features/directives/once.spec.js @@ -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: '
{{ name }}
' + } + }, + template: ` +
+ + +
+ ` + }).$mount() + waitForUpdate(() => { + expect(vm.$el.children[0].innerHTML).toBe('a') + expect(vm.$el.children[1].innerHTML).toBe('b') + }).then(done) + }) }) function expectTextContent (vm, text) {