From 52608302e9bca84fb9e9f0499e89acade78d3d07 Mon Sep 17 00:00:00 2001 From: contribu Date: Sat, 17 Apr 2021 00:58:02 +0900 Subject: [PATCH] fix(core): fix sameVnode for async component (#11107) Co-authored-by: mac2 --- src/core/vdom/patch.js | 4 ++-- .../modules/vdom/patch/edge-cases.spec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 2052df91..bff48f44 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -34,7 +34,8 @@ const hooks = ['create', 'activate', 'update', 'remove', 'destroy'] function sameVnode (a, b) { return ( - a.key === b.key && ( + a.key === b.key && + a.asyncFactory === b.asyncFactory && ( ( a.tag === b.tag && a.isComment === b.isComment && @@ -42,7 +43,6 @@ function sameVnode (a, b) { sameInputType(a, b) ) || ( isTrue(a.isAsyncPlaceholder) && - a.asyncFactory === b.asyncFactory && isUndef(b.asyncFactory.error) ) ) diff --git a/test/unit/modules/vdom/patch/edge-cases.spec.js b/test/unit/modules/vdom/patch/edge-cases.spec.js index a7f7ba38..24d97a63 100644 --- a/test/unit/modules/vdom/patch/edge-cases.spec.js +++ b/test/unit/modules/vdom/patch/edge-cases.spec.js @@ -1,4 +1,5 @@ import Vue from 'vue' +import { SSR_ATTR } from 'shared/constants' describe('vdom patch: edge cases', () => { // exposed by #3406 @@ -432,4 +433,22 @@ describe('vdom patch: edge cases', () => { expect(vm.$el.textContent).not.toMatch('Infinity') }).then(done) }) + + it('should not throw when hydrated pending async component is patched by v-if="false"', done => { + const PendingAsyncComponent = () => new Promise(() => {}) + const ssrAsyncComponent = document.createElement('div') + ssrAsyncComponent.setAttribute(SSR_ATTR, 'true') + const vm = new Vue({ + data: { + visible: true + }, + components: { + PendingAsyncComponent + }, + template: '' + }).$mount(ssrAsyncComponent) + + vm.visible = false + vm.$nextTick(done) + }) })