From e26b86290ee386eefcda362f936574d656f5babd Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Mon, 15 Aug 2022 19:05:12 -0400 Subject: [PATCH 1/2] Fix hooks calling shouldComponentUpdate without context This was breaking code that relies on `this` within shouldComponentUpdate. --- hooks/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/src/index.js b/hooks/src/index.js index d838d17356..bc0e43223c 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -193,7 +193,7 @@ export function useReducer(reducer, initialState, init) { // When we have no updated hooks in the component we invoke the previous SCU or // traverse the VDOM tree further. if (allHooksEmpty) { - return prevScu ? prevScu(p, s, c) : true; + return prevScu ? prevScu.call(this, p, s, c) : true; } // We check whether we have components with a nextValue set that @@ -208,7 +208,7 @@ export function useReducer(reducer, initialState, init) { }); if (!shouldSkipUpdating) { - return prevScu ? prevScu(p, s, c) : true; + return prevScu ? prevScu.call(this, p, s, c) : true; } // When all set nextValues are equal to their original value From 80de59b7f30663c4a05d26b8714d02c551715aa2 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Mon, 15 Aug 2022 19:21:50 -0400 Subject: [PATCH 2/2] Fix `this` usage --- hooks/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/src/index.js b/hooks/src/index.js index bc0e43223c..b0fb376d5e 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -184,7 +184,7 @@ export function useReducer(reducer, initialState, init) { if (!currentComponent._hasScuFromHooks) { currentComponent._hasScuFromHooks = true; const prevScu = currentComponent.shouldComponentUpdate; - currentComponent.shouldComponentUpdate = (p, s, c) => { + currentComponent.shouldComponentUpdate = function (p, s, c) { if (!hookState._component.__hooks) return true; const stateHooks = hookState._component.__hooks._list.filter( x => x._component