From bbcd1d6c62a0f28e59a42558ef6f8866be3e81bc Mon Sep 17 00:00:00 2001 From: Viraj Ajay Joshi Date: Tue, 11 Jun 2024 19:53:08 +0530 Subject: [PATCH] fix: web injection in head --- .../gluestack-ui-provider/index.web.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/example/storybook-nativewind/src/core-components/nativewind/gluestack-ui-provider/index.web.tsx b/example/storybook-nativewind/src/core-components/nativewind/gluestack-ui-provider/index.web.tsx index ab39b596e..08db02d87 100644 --- a/example/storybook-nativewind/src/core-components/nativewind/gluestack-ui-provider/index.web.tsx +++ b/example/storybook-nativewind/src/core-components/nativewind/gluestack-ui-provider/index.web.tsx @@ -1,5 +1,5 @@ 'use client'; -import React from 'react'; +import React, { useEffect } from 'react'; import { config } from './config'; import { OverlayProvider } from '@gluestack-ui/overlay'; import { ToastProvider } from '@gluestack-ui/toast'; @@ -24,20 +24,24 @@ export function GluestackUIProvider({ acc += `${cur}:${config[mode][cur]};`; return acc; }, ''); + setFlushStyles(`:root {${stringcssvars}} `); - if (config[mode] && typeof document !== 'undefined') { - const element = document.documentElement; - if (element) { - const head = element.querySelector('head'); - let style = head?.querySelector(`[id='${styleTagId}']`); - if (!style) { - style = createStyle(styleTagId); + useEffect(() => { + if (config[mode] && typeof document !== 'undefined') { + const element = document.documentElement; + if (element) { + const head = element.querySelector('head'); + let style = head?.querySelector(`[id='${styleTagId}']`); + if (!style) { + style = createStyle(styleTagId); + } + style.innerHTML = `:root {${stringcssvars}} `; + if (head) head.appendChild(style); } - style.innerHTML = `:root {${stringcssvars}} `; - if (head) head.appendChild(style); } - } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [mode]); return (