Skip to content

Commit 2572294

Browse files
RoyEJohnsonCopilot
andauthored
Copilot suggestion
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7f9703c commit 2572294

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

src/components/ManageCookies.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@ export const ManageCookiesLink = ({children, className, wrapper, ...props}: Mana
1616
const styleElementRef = React.useRef<HTMLStyleElement | null>(null);
1717

1818
// Inject global style to hide CookieYes revisit button when component mounts
19-
React.useLayoutEffect(() => {
20-
if (inBrowser && !styleElementRef.current) {
21-
const style = document.createElement('style');
22-
style.textContent = '.cky-btn-revisit { display: none; }';
23-
document.head.appendChild(style);
24-
styleElementRef.current = style;
25-
26-
return () => {
27-
if (styleElementRef.current) {
28-
document.head.removeChild(styleElementRef.current);
29-
styleElementRef.current = null;
30-
}
31-
};
32-
}
33-
return;
19+
const useIsomorphicLayoutEffect = inBrowser ? React.useLayoutEffect : React.useEffect;
20+
21+
useIsomorphicLayoutEffect(() => {
22+
if (!inBrowser || styleElementRef.current) return;
23+
24+
const style = document.createElement('style');
25+
style.textContent = '.cky-btn-revisit { display: none; }';
26+
document.head.appendChild(style);
27+
styleElementRef.current = style;
28+
29+
return () => {
30+
style.remove();
31+
styleElementRef.current = null;
32+
};
3433
}, [inBrowser]);
3534

3635
React.useEffect(() => {

0 commit comments

Comments
 (0)