From 368393ad87f8129366598c511886e45ff0bc6a90 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 13 May 2024 11:44:34 +0200 Subject: [PATCH] fix global not defined issue --- .gitignore | 1 + ...-event-listener-npm-0.1.7-56ef42a654.patch | 21 +++++++++++++++++++ package.json | 7 +++++-- src/App.tsx | 2 +- src/components/Header/Header.tsx | 2 +- yarn.lock | 11 +++++++++- 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch diff --git a/.gitignore b/.gitignore index 57876553..97f519d1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ yarn-error.log* # Yarn berry /**/.yarn/* !/**/.yarn/releases +!/**/.yarn/patches !/**/.yarn/plugins !/**/.yarn/sdks !/**/.yarn/versions diff --git a/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch b/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch new file mode 100644 index 00000000..fc1b4719 --- /dev/null +++ b/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch @@ -0,0 +1,21 @@ +diff --git a/dist/event-listener.js b/dist/event-listener.js +index 237ce88887b5ecc20945dc01e00f2b23323c2392..f3cb0df84ae93ab10d9227387e5d6e2c46398274 100644 +--- a/dist/event-listener.js ++++ b/dist/event-listener.js +@@ -1 +1 @@ +-var e=require("react");module.exports=function(n,r,t,u){void 0===t&&(t=global),void 0===u&&(u={});var c=e.useRef(),i=u.capture,o=u.passive,a=u.once;e.useEffect(function(){c.current=r},[r]),e.useEffect(function(){if(t&&t.addEventListener){var e=function(e){return c.current(e)},r={capture:i,passive:o,once:a};return t.addEventListener(n,e,r),function(){t.removeEventListener(n,e,r)}}},[n,t,i,o,a])}; ++var e=require("react");module.exports=function(n,r,t,u){void 0===t&&(t=globalThis),void 0===u&&(u={});var c=e.useRef(),i=u.capture,o=u.passive,a=u.once;e.useEffect(function(){c.current=r},[r]),e.useEffect(function(){if(t&&t.addEventListener){var e=function(e){return c.current(e)},r={capture:i,passive:o,once:a};return t.addEventListener(n,e,r),function(){t.removeEventListener(n,e,r)}}},[n,t,i,o,a])}; +diff --git a/dist/event-listener.m.js b/dist/event-listener.m.js +index 064342caa68ec6f96ffb07315dfdea8f3eea8526..c6a88a7c26d903a6bcb11659d14663a22f6b3e14 100644 +--- a/dist/event-listener.m.js ++++ b/dist/event-listener.m.js +@@ -1 +1 @@ +-import{useRef as e,useEffect as n}from"react";export default function(t,r,i,o){void 0===i&&(i=global),void 0===o&&(o={});var c=e(),u=o.capture,a=o.passive,v=o.once;n(function(){c.current=r},[r]),n(function(){if(i&&i.addEventListener){var e=function(e){return c.current(e)},n={capture:u,passive:a,once:v};return i.addEventListener(t,e,n),function(){i.removeEventListener(t,e,n)}}},[t,i,u,a,v])} ++import{useRef as e,useEffect as n}from"react";export default function(t,r,i,o){void 0===i&&(i=globalThis),void 0===o&&(o={});var c=e(),u=o.capture,a=o.passive,v=o.once;n(function(){c.current=r},[r]),n(function(){if(i&&i.addEventListener){var e=function(e){return c.current(e)},n={capture:u,passive:a,once:v};return i.addEventListener(t,e,n),function(){i.removeEventListener(t,e,n)}}},[t,i,u,a,v])} +diff --git a/dist/event-listener.modern.js b/dist/event-listener.modern.js +index 8f4b8201ea08b0c7d2a295b53cd6263f8ce1bb7e..c3b91c1fddb52da998a460f5127202db264c93c3 100644 +--- a/dist/event-listener.modern.js ++++ b/dist/event-listener.modern.js +@@ -1 +1 @@ +-import{useRef as e,useEffect as r}from"react";export default(t,n,a=global,c={})=>{const o=e(),{capture:s,passive:i,once:u}=c;r(()=>{o.current=n},[n]),r(()=>{if(!a||!a.addEventListener)return;const e=e=>o.current(e),r={capture:s,passive:i,once:u};return a.addEventListener(t,e,r),()=>{a.removeEventListener(t,e,r)}},[t,a,s,i,u])}; ++import{useRef as e,useEffect as r}from"react";export default(t,n,a=globalThis,c={})=>{const o=e(),{capture:s,passive:i,once:u}=c;r(()=>{o.current=n},[n]),r(()=>{if(!a||!a.addEventListener)return;const e=e=>o.current(e),r={capture:s,passive:i,once:u};return a.addEventListener(t,e,r),()=>{a.removeEventListener(t,e,r)}},[t,a,s,i,u])}; diff --git a/package.json b/package.json index 255d4bf6..e3972407 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "build-storybook:test": "storybook build --output-dir build/storybook --test", "build-all": "yarn build && yarn build-storybook", "chromatic": "chromatic --project-token $CHROMATIC_PROJECT_TOKEN --exit-zero-on-changes --only-changed", - "prepare": "husky install", + "prepare": "husky", "lint": "eslint --fix .", "prettier": "prettier --write .", "pre-commit": "lint-staged", @@ -124,5 +124,8 @@ "*.{ts,tsx}": "eslint --fix", "*.{html,md}": "prettier --write" }, - "packageManager": "yarn@4.2.1" + "packageManager": "yarn@4.2.1", + "resolutions": { + "@use-it/event-listener@npm:^0.1.2": "patch:@use-it/event-listener@npm%3A0.1.7#~/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch" + } } diff --git a/src/App.tsx b/src/App.tsx index 8440ec57..2f64be60 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,7 @@ import { lightTheme, darkTheme } from './styles/theme' import { GlobalStyle } from './styles/GlobalStyle' export default function App() { - const { value } = useDarkMode(false) + const { value } = useDarkMode(false, { global: globalThis.window }) const theme = value ? darkTheme : lightTheme return ( diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 05b4c9c9..6e0ba60a 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -100,7 +100,7 @@ export const CartTotal = styled(Body)( ) const ThemeToggle = () => { - const darkMode = useDarkMode(false) + const darkMode = useDarkMode(false, { global: globalThis.window }) return (