From 7348758aa318d5176ee722bb700d196c2c9c18db Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Tue, 4 Nov 2025 09:46:53 +0100 Subject: [PATCH] fix: hot reloading css --- packages/uniwind/src/components/native/useStyle.ts | 2 +- packages/uniwind/src/core/native/store.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/uniwind/src/components/native/useStyle.ts b/packages/uniwind/src/components/native/useStyle.ts index 8f1fd7ca..434752e3 100644 --- a/packages/uniwind/src/components/native/useStyle.ts +++ b/packages/uniwind/src/components/native/useStyle.ts @@ -14,7 +14,7 @@ export const useStyle = (className?: string, state?: ComponentState) => { ) useEffect(() => { - if (styleState.dependencies.length > 0) { + if (__DEV__ || styleState.dependencies.length > 0) { const dispose = UniwindStore.subscribe(() => rerender(), styleState.dependencies) return dispose diff --git a/packages/uniwind/src/core/native/store.ts b/packages/uniwind/src/core/native/store.ts index a1b1814e..bd4a1bda 100644 --- a/packages/uniwind/src/core/native/store.ts +++ b/packages/uniwind/src/core/native/store.ts @@ -24,10 +24,15 @@ class UniwindStoreBuilder { [StyleDependency.FontScale]: new Set<() => void>(), [StyleDependency.Rtl]: new Set<() => void>(), } + private hotReloadListeners = new Set<() => void>() private cache = new Map() private generateStyleSheetCallbackResult: ReturnType | null = null subscribe(onStoreChange: () => void, dependencies: Array) { + if (__DEV__) { + this.hotReloadListeners.add(onStoreChange) + } + dependencies.forEach(dep => { this.listeners[dep].add(onStoreChange) }) @@ -36,6 +41,10 @@ class UniwindStoreBuilder { dependencies.forEach(dep => { this.listeners[dep].delete(onStoreChange) }) + + if (__DEV__) { + this.hotReloadListeners.delete(onStoreChange) + } } } @@ -90,6 +99,10 @@ class UniwindStoreBuilder { if (platformVars) { Object.defineProperties(this.vars, Object.getOwnPropertyDescriptors(platformVars)) } + + if (__DEV__ && generateStyleSheetCallback) { + this.hotReloadListeners.forEach(listener => listener()) + } } notifyListeners = (dependencies: Array) => {