Skip to content

Commit

Permalink
fix global not defined issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed May 13, 2024
1 parent 364406e commit 368393a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ yarn-error.log*
# Yarn berry
/**/.yarn/*
!/**/.yarn/releases
!/**/.yarn/patches
!/**/.yarn/plugins
!/**/.yarn/sdks
!/**/.yarn/versions
Expand Down
21 changes: 21 additions & 0 deletions .yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch
Original file line number Diff line number Diff line change
@@ -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])};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const CartTotal = styled(Body)(
)

const ThemeToggle = () => {
const darkMode = useDarkMode(false)
const darkMode = useDarkMode(false, { global: globalThis.window })
return (
<Button
round
Expand Down
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5306,7 +5306,7 @@ __metadata:
languageName: node
linkType: hard

"@use-it/event-listener@npm:^0.1.2":
"@use-it/event-listener@npm:0.1.7":
version: 0.1.7
resolution: "@use-it/event-listener@npm:0.1.7"
peerDependencies:
Expand All @@ -5315,6 +5315,15 @@ __metadata:
languageName: node
linkType: hard

"@use-it/event-listener@patch:@use-it/event-listener@npm%3A0.1.7#~/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch":
version: 0.1.7
resolution: "@use-it/event-listener@patch:@use-it/event-listener@npm%3A0.1.7#~/.yarn/patches/@use-it-event-listener-npm-0.1.7-56ef42a654.patch::version=0.1.7&hash=4e5cf2"
peerDependencies:
react: ">=16.8.0"
checksum: 10c0/a12ca843f43d4c53d317df4de82af38b435e778683af33cf3e83313b99636cbaae86c6151207da00eb4bebf951cabcd3a72624550a9eb17870b846e74e117f1d
languageName: node
linkType: hard

"@vitejs/plugin-react-swc@npm:^3.6.0":
version: 3.6.0
resolution: "@vitejs/plugin-react-swc@npm:3.6.0"
Expand Down

0 comments on commit 368393a

Please sign in to comment.