Skip to content

Commit

Permalink
fix: web injection in head
Browse files Browse the repository at this point in the history
  • Loading branch information
Viraj Ajay Joshi authored and Viraj Ajay Joshi committed Jun 11, 2024
1 parent 38e34de commit bbcd1d6
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<OverlayProvider>
Expand Down

0 comments on commit bbcd1d6

Please sign in to comment.