Skip to content

Commit

Permalink
Merge pull request #2215 from gluestack/fix/gluestack-ui-provider-sty…
Browse files Browse the repository at this point in the history
…le-injection

fix: multiple style injection
  • Loading branch information
surajahmed authored Jun 4, 2024
2 parents c4d827e + 9e07c61 commit 86118d5
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { OverlayProvider } from '@gluestack-ui/overlay';
import { ToastProvider } from '@gluestack-ui/toast';
import { setFlushStyles } from '@gluestack-ui/nativewind-utils/flush';

const styleTagId = 'gluestack-ui-nativewind';
const createStyle = (styleTagId: any) => {
let style = document.createElement('style');
style.id = styleTagId;
style.appendChild(document.createTextNode(''));
return style;
};

export function GluestackUIProvider({
mode = 'light',
...props
Expand All @@ -22,7 +30,10 @@ export function GluestackUIProvider({
const element = document.documentElement;
if (element) {
const head = element.querySelector('head');
const style = document.createElement('style');
let style = head?.querySelector(`[id='${styleTagId}']`);
if (!style) {
style = createStyle(styleTagId);
}
style.innerHTML = `:root {${stringcssvars}} `;
if (head) head.appendChild(style);
}
Expand Down

0 comments on commit 86118d5

Please sign in to comment.