Skip to content

Commit d2fdae0

Browse files
vladarpieh
authored andcommitted
fix(gatsby-cli): Clean up on unmount in the ink logger (#19312)
1 parent 55a41c7 commit d2fdae0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/gatsby-cli/src/reporter/loggers/ink/context.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ export const StoreStateProvider = ({ children }) => {
88
const [state, setState] = useState(getStore().getState())
99

1010
useEffect(() => {
11-
onLogAction(() => {
11+
const unsubscribe = onLogAction(() => {
1212
setState(getStore().getState())
1313
})
14+
return unsubscribe
1415
}, [])
1516

1617
return (

packages/gatsby-cli/src/reporter/redux/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let store = Redux.createStore(
1111
)
1212

1313
const storeSwapListeners = []
14-
const onLogActionListeners = []
14+
const onLogActionListeners = new Set()
1515

1616
const isInternalAction = action => {
1717
if (
@@ -58,15 +58,18 @@ const iface = {
5858
// deal with actions needed just for internal tracking of status
5959
return
6060
}
61-
onLogActionListeners.forEach(fn => {
61+
for (const fn of onLogActionListeners) {
6262
fn(action)
63-
})
63+
}
6464
},
6565
onStoreSwap: fn => {
6666
storeSwapListeners.push(fn)
6767
},
6868
onLogAction: fn => {
69-
onLogActionListeners.push(fn)
69+
onLogActionListeners.add(fn)
70+
return () => {
71+
onLogActionListeners.delete(fn)
72+
}
7073
},
7174
setStore: s => {
7275
s.dispatch({

0 commit comments

Comments
 (0)