]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hmr): force full diff on HMR
authorEvan You <yyx990803@gmail.com>
Fri, 13 Dec 2019 22:57:21 +0000 (17:57 -0500)
committerEvan You <yyx990803@gmail.com>
Fri, 13 Dec 2019 22:57:21 +0000 (17:57 -0500)
packages/runtime-core/src/renderer.ts

index ba981f4f92f8ca9c76d9a061b029114b1d2deb7e..4747ed6d512c771db74da07cbf97558fcbfed3a0 100644 (file)
@@ -55,6 +55,8 @@ import { ErrorCodes, callWithErrorHandling } from './errorHandling'
 import { KeepAliveSink, isKeepAlive } from './components/KeepAlive'
 import { registerHMR, unregisterHMR } from './hmr'
 
+const __HMR__ = __BUNDLER__ && __DEV__
+
 export interface RendererOptions<HostNode = any, HostElement = any> {
   patchProp(
     el: HostElement,
@@ -442,7 +444,7 @@ export function createRenderer<
     optimized: boolean
   ) {
     const el = (n2.el = n1.el) as HostElement
-    const { patchFlag, dynamicChildren } = n2
+    let { patchFlag, dynamicChildren } = n2
     const oldProps = (n1 && n1.props) || EMPTY_OBJ
     const newProps = n2.props || EMPTY_OBJ
 
@@ -450,6 +452,12 @@ export function createRenderer<
       invokeDirectiveHook(newProps.onVnodeBeforeUpdate, parentComponent, n2, n1)
     }
 
+    if (__HMR__ && parentComponent && parentComponent.renderUpdated) {
+      // HMR updated, force full diff
+      patchFlag = 0
+      optimized = false
+    }
+
     if (patchFlag > 0) {
       // the presence of a patchFlag means this element's render code was
       // generated by the compiler and can take the fast path.
@@ -654,10 +662,18 @@ export function createRenderer<
     const fragmentEndAnchor = (n2.anchor = n1
       ? n1.anchor
       : hostCreateComment(showID ? `fragment-${devFragmentID}-end` : ''))!
-    const { patchFlag } = n2
+
+    let { patchFlag } = n2
     if (patchFlag > 0) {
       optimized = true
     }
+
+    if (__HMR__ && parentComponent && parentComponent.renderUpdated) {
+      // HMR updated, force full diff
+      patchFlag = 0
+      optimized = false
+    }
+
     if (n1 == null) {
       if (showID) {
         devFragmentID++
@@ -879,8 +895,7 @@ export function createRenderer<
       parentComponent
     ))
 
-    // HMR
-    if (__BUNDLER__ && __DEV__ && instance.type.__hmrId != null) {
+    if (__HMR__ && instance.type.__hmrId != null) {
       registerHMR(instance)
     }
 
@@ -1572,8 +1587,7 @@ export function createRenderer<
     parentSuspense: HostSuspenseBoundary | null,
     doRemove?: boolean
   ) {
-    // HMR
-    if (__BUNDLER__ && __DEV__ && instance.type.__hmrId != null) {
+    if (__HMR__ && instance.type.__hmrId != null) {
       unregisterHMR(instance)
     }