From 74409101a2617e606ef16dd4a2e5d7cfcc34df7a Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Fri, 10 Jan 2025 14:24:16 +0100 Subject: [PATCH 1/5] fix: disable multiple runs of configure on SSR --- src/web/state.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/web/state.ts b/src/web/state.ts index cfbf4dd5..12f0f044 100644 --- a/src/web/state.ts +++ b/src/web/state.ts @@ -10,6 +10,7 @@ import type { UnistylesServices } from './types' type UnistylesSettings = Partial['settings']>> export class UnistylesState { + isInitialized = false themes = new Map() cssThemes = new Map() themeName?: AppThemeName @@ -32,6 +33,11 @@ export class UnistylesState { constructor(private services: UnistylesServices) {} init = (config: UnistylesConfig) => { + if (this.isInitialized) { + return + } + + this.isInitialized = true this.initThemes(config.themes, config.settings?.CSSVars) this.initBreakpoints(config.breakpoints) From 0bee095a16fd0bab9d69c9596b4c6a7a4dcca909 Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Fri, 10 Jan 2025 14:24:34 +0100 Subject: [PATCH 2/5] chore: remove hydration script --- src/server/useServerUnistyles.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/useServerUnistyles.tsx b/src/server/useServerUnistyles.tsx index 7d33d368..407b5d56 100644 --- a/src/server/useServerUnistyles.tsx +++ b/src/server/useServerUnistyles.tsx @@ -5,6 +5,7 @@ import { UnistylesWeb } from '../web' declare global { interface Window { + // @ts-ignore __UNISTYLES_STATE__: ReturnType } } @@ -36,5 +37,6 @@ export const useServerUnistyles = () => { if (typeof window !== 'undefined') { UnistylesWeb.registry.css.hydrate(window.__UNISTYLES_STATE__) + document.querySelector('#unistyles-script')?.remove() } } From 129690aa1d31179678aa962a73bf0e8631959293 Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Fri, 10 Jan 2025 15:12:16 +0100 Subject: [PATCH 3/5] fix: remove styles from mq --- src/web/css/state.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/web/css/state.ts b/src/web/css/state.ts index b1f7d057..393a444e 100644 --- a/src/web/css/state.ts +++ b/src/web/css/state.ts @@ -93,6 +93,9 @@ export class CSSState { this.mainMap.forEach(styles => { styles.delete(hash) }) + this.mqMap.forEach(styles => { + styles.delete(hash) + }) if (this.styleTag) { this.styleTag.innerText = this.getStyles() From e047841994d9774f27d4861591bdc49530af7b46 Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Fri, 10 Jan 2025 15:12:33 +0100 Subject: [PATCH 4/5] fix: fix removing styles from static --- src/web/registry.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/web/registry.ts b/src/web/registry.ts index efe59aca..954b3047 100644 --- a/src/web/registry.ts +++ b/src/web/registry.ts @@ -75,9 +75,16 @@ export class UnistylesRegistry { stylesCounter.delete(ref) - if (stylesCounter.size === 0 && !document.querySelector(`.${hash}`)) { - this.css.remove(hash) - this.stylesCache.delete(hash) + if (stylesCounter.size === 0) { + // Move this to the end of the event loop so the element is removed from the DOM + Promise.resolve().then(() => { + if (document.querySelector(`.${hash}`)) { + return + } + + this.css.remove(hash) + this.stylesCache.delete(hash) + }) return true } From 535099047840fa68191c723451780939dc7c15e1 Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Mon, 13 Jan 2025 07:37:34 +0100 Subject: [PATCH 5/5] fix: aspect-ratio parsing --- src/web/convert/style.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/web/convert/style.ts b/src/web/convert/style.ts index eb6f8f9a..392678f1 100644 --- a/src/web/convert/style.ts +++ b/src/web/convert/style.ts @@ -53,7 +53,8 @@ const CSS_NUMBER_KEYS = new Set([ 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', - 'strokeWidth' + 'strokeWidth', + 'aspectRatio' ]) const convertMap = {