From 96eb7452548293c343613ab778248a5da9619f45 Mon Sep 17 00:00:00 2001 From: Yaroslav Sych Date: Tue, 30 Aug 2022 09:42:22 +0300 Subject: [PATCH] fix(hmr): fix HMR for nested non-SFC components (#4077) --- packages/runtime-core/src/componentProps.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 51b77c56175..09b487811b5 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -192,6 +192,13 @@ export function initProps( instance.attrs = attrs } +function isInHmrContext(instance: ComponentInternalInstance | null) { + while (instance) { + if (instance.type.__hmrId) return true + instance = instance.parent + } +} + export function updateProps( instance: ComponentInternalInstance, rawProps: Data | null, @@ -211,11 +218,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__ && isInHmrContext(instance)) && (optimized || patchFlag > 0) && !(patchFlag & PatchFlags.FULL_PROPS) ) {