fix(hmr): force full diff on HMR

This commit is contained in:
Evan You 2019-12-13 17:57:21 -05:00
parent b15951e190
commit d6acb9c073

View File

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