@@ -182,15 +182,37 @@ export function useReducer(reducer, initialState, init) {
182182 hookState . _internal = currentInternal ;
183183 if ( ! currentInternal . data . _hasScuFromHooks ) {
184184 currentInternal . data . _hasScuFromHooks = true ;
185- const prevScu = currentInternal . _component . shouldComponentUpdate ;
185+ let prevScu = currentInternal . _component . shouldComponentUpdate ;
186+ const prevCWU = currentInternal . _component . componentWillUpdate ;
187+
188+ // If we're dealing with a forced update `shouldComponentUpdate` will
189+ // not be called. But we use that to update the hook values, so we
190+ // need to call it.
191+ currentInternal . _component . componentWillUpdate = function ( p , s , c ) {
192+ if ( this . _force ) {
193+ let tmp = prevScu ;
194+ // Clear to avoid other sCU hooks from being called
195+ prevScu = undefined ;
196+ updateHookState ( p , s , c ) ;
197+ prevScu = tmp ;
198+ }
199+
200+ if ( prevCWU ) prevCWU . call ( this , p , s , c ) ;
201+ } ;
186202
187203 // This SCU has the purpose of bailing out after repeated updates
188204 // to stateful hooks.
189205 // we store the next value in _nextValue[0] and keep doing that for all
190206 // state setters, if we have next states and
191207 // all next states within a component end up being equal to their original state
192208 // we are safe to bail out for this specific component.
193- currentInternal . _component . shouldComponentUpdate = function ( p , s , c ) {
209+ /**
210+ *
211+ * @type {import('./internal').Component["shouldComponentUpdate"] }
212+ */
213+ // @ts -ignore - We don't use TS to downtranspile
214+ // eslint-disable-next-line no-inner-declarations
215+ function updateHookState ( p , s , c ) {
194216 if ( ! hookState . _internal . data . __hooks ) return true ;
195217
196218 const stateHooks = hookState . _internal . data . __hooks . _list . filter (
@@ -221,7 +243,9 @@ export function useReducer(reducer, initialState, init) {
221243 ? prevScu . call ( this , p , s , c )
222244 : true
223245 : false ;
224- } ;
246+ }
247+
248+ currentInternal . _component . shouldComponentUpdate = updateHookState ;
225249 }
226250 }
227251
0 commit comments