From fd7883dc2929a11ca0d2696c388e744713a8ab6c Mon Sep 17 00:00:00 2001 From: Turrsis Date: Wed, 7 Jul 2021 18:51:56 +0300 Subject: [PATCH 1/2] fix(hmr): properly force hmr full component which uses directives props update --- packages/runtime-core/src/componentProps.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index c4ab05dd021..823ec64cac2 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -178,6 +178,19 @@ export function initProps( instance.attrs = attrs } +function inHmrContext(instance: ComponentInternalInstance) { + if (instance.type.__hmrId) { + return instance.type.__hmrId + } + let parent = instance.parent + while (parent) { + if (parent.type.__file) { + return parent.type.__hmrId + } + parent = parent.parent + } +} + export function updateProps( instance: ComponentInternalInstance, rawProps: Data | null, @@ -197,11 +210,7 @@ export function updateProps( // always force full diff in dev // - #1942 if hmr is enabled with sfc component // - vite#872 non-sfc component used by sfc component - !( - __DEV__ && - (instance.type.__hmrId || - (instance.parent && instance.parent.type.__hmrId)) - ) && + !(__DEV__ && inHmrContext(instance)) && (optimized || patchFlag > 0) && !(patchFlag & PatchFlags.FULL_PROPS) ) { From 68809eb94c6c233b7de4f0bb6c8d796dc2825bad Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 30 Aug 2022 02:25:22 -0400 Subject: [PATCH 2/2] Update componentProps.ts --- packages/runtime-core/src/componentProps.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 823ec64cac2..4ac5c4c7867 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -178,16 +178,10 @@ export function initProps( instance.attrs = attrs } -function inHmrContext(instance: ComponentInternalInstance) { - if (instance.type.__hmrId) { - return instance.type.__hmrId - } - let parent = instance.parent - while (parent) { - if (parent.type.__file) { - return parent.type.__hmrId - } - parent = parent.parent +function isInHmrContext(instance: ComponentInternalInstance | null) { + while (instance) { + if (instance.type.__hmrId) return true + instance = instance.parent } } @@ -210,7 +204,7 @@ export function updateProps( // always force full diff in dev // - #1942 if hmr is enabled with sfc component // - vite#872 non-sfc component used by sfc component - !(__DEV__ && inHmrContext(instance)) && + !(__DEV__ && isInHmrContext(instance)) && (optimized || patchFlag > 0) && !(patchFlag & PatchFlags.FULL_PROPS) ) {