From b103b7570d0a0bb2c8cad20ee26c95278dcfa84f Mon Sep 17 00:00:00 2001 From: Zev Zhu <45655660+aibayanyu20@users.noreply.github.com> Date: Wed, 3 May 2023 13:24:28 +0800 Subject: [PATCH] fix: dealing with switching topics modal, notification, message does not take effect close #6512 (#6518) * fix: resolve dark mode not support * fix: unified expression --- components/theme/internal.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/theme/internal.ts b/components/theme/internal.ts index aee0e5ba8..d6811ed44 100644 --- a/components/theme/internal.ts +++ b/components/theme/internal.ts @@ -21,7 +21,7 @@ import statisticToken, { merge as mergeToken, statistic } from './util/statistic import type { VueNode } from '../_util/type'; import { objectType } from '../_util/type'; import type { ComputedRef, InjectionKey, Ref } from 'vue'; -import { defineComponent, provide, computed, inject } from 'vue'; +import { defineComponent, provide, computed, inject, watchEffect, ref } from 'vue'; import { toReactive } from '../_util/toReactive'; const defaultTheme = createTheme(defaultDerivative); @@ -63,12 +63,17 @@ export interface DesignTokenContext { //defaultConfig const DesignTokenContextKey: InjectionKey = Symbol('DesignTokenContext'); +export const globalDesignTokenApi = ref(); + export const useDesignTokenProvider = (value: DesignTokenContext) => { provide(DesignTokenContextKey, value); + watchEffect(() => { + globalDesignTokenApi.value = value; + }); }; export const useDesignTokenInject = () => { - return inject(DesignTokenContextKey, defaultConfig); + return inject(DesignTokenContextKey, globalDesignTokenApi.value || defaultConfig); }; export const DesignTokenProvider = defineComponent({ props: { @@ -87,7 +92,10 @@ export function useToken(): [ ComputedRef, ComputedRef, ] { - const designTokenContext = inject(DesignTokenContextKey, defaultConfig); + const designTokenContext = inject( + DesignTokenContextKey, + globalDesignTokenApi.value || defaultConfig, + ); const salt = computed(() => `${version}-${designTokenContext.hashed || ''}`);