From f553a87037235065f9d66b8c8f98740786ce8248 Mon Sep 17 00:00:00 2001 From: ShuGang Zhou Date: Mon, 4 Sep 2023 22:21:56 +0800 Subject: [PATCH] chore(ConfigProvider): update var name and init execute the sync function twice (#12248) --- .../src/config-provider/ConfigProvider.tsx | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/vant/src/config-provider/ConfigProvider.tsx b/packages/vant/src/config-provider/ConfigProvider.tsx index 7ff2105d5..a5ecfda1a 100644 --- a/packages/vant/src/config-provider/ConfigProvider.tsx +++ b/packages/vant/src/config-provider/ConfigProvider.tsx @@ -113,25 +113,19 @@ export default defineComponent({ onDeactivated(removeTheme); onBeforeUnmount(removeTheme); - watch( - style, - (newStyle, oldStyle) => { - if (props.themeVarsScope === 'global') { - syncThemeVarsOnRoot( - newStyle as Record, - oldStyle as Record, - ); - } - }, - { - immediate: true, - }, - ); + watch(style, (newStyle, oldStyle) => { + if (props.themeVarsScope === 'global') { + syncThemeVarsOnRoot( + newStyle as Record, + oldStyle as Record, + ); + } + }); watch( () => props.themeVarsScope, - (newScope, oldStyle) => { - if (oldStyle === 'global') { + (newScope, oldScope) => { + if (oldScope === 'global') { // remove on Root syncThemeVarsOnRoot({}, style.value as Record); } @@ -140,10 +134,12 @@ export default defineComponent({ syncThemeVarsOnRoot(style.value as Record, {}); } }, - { - immediate: true, - }, ); + + if (props.themeVarsScope === 'global') { + // add on root + syncThemeVarsOnRoot(style.value as Record, {}); + } } provide(CONFIG_PROVIDER_KEY, props);