@@ -34,6 +34,8 @@ import {
34
34
} from './ReactFiberScheduler' ;
35
35
36
36
import invariant from 'shared/invariant' ;
37
+ import warning from 'shared/warning' ;
38
+ import getComponentName from 'shared/getComponentName' ;
37
39
import areHookInputsEqual from 'shared/areHookInputsEqual' ;
38
40
import { markWorkInProgressReceivedUpdate } from './ReactFiberBeginWork' ;
39
41
@@ -104,8 +106,6 @@ let componentUpdateQueue: FunctionComponentUpdateQueue | null = null;
104
106
// map of queue -> render-phase updates, which are discarded once the component
105
107
// completes without re-rendering.
106
108
107
- // Whether the work-in-progress hook is a re-rendered hook
108
- let isReRender : boolean = false ;
109
109
// Whether an update was scheduled during the currently executing render pass.
110
110
let didScheduleRenderPhaseUpdate : boolean = false ;
111
111
// Lazily created map of render-phase updates
@@ -147,7 +147,6 @@ export function renderWithHooks(
147
147
// remainingExpirationTime = NoWork;
148
148
// componentUpdateQueue = null;
149
149
150
- // isReRender = false;
151
150
// didScheduleRenderPhaseUpdate = false;
152
151
// renderPhaseUpdates = null;
153
152
// numberOfReRenders = -1;
@@ -163,6 +162,21 @@ export function renderWithHooks(
163
162
componentUpdateQueue = null ;
164
163
165
164
children = Component ( props , refOrContext ) ;
165
+
166
+ if ( __DEV__ ) {
167
+ if (
168
+ current !== null &&
169
+ workInProgressHook !== null &&
170
+ currentHook === null
171
+ ) {
172
+ warning (
173
+ false ,
174
+ '%s: Rendered more hooks than during the previous render. This is ' +
175
+ 'not currently supported and may lead to unexpected behavior.' ,
176
+ getComponentName ( Component ) ,
177
+ ) ;
178
+ }
179
+ }
166
180
} while ( didScheduleRenderPhaseUpdate ) ;
167
181
168
182
renderPhaseUpdates = null ;
@@ -188,9 +202,6 @@ export function renderWithHooks(
188
202
remainingExpirationTime = NoWork ;
189
203
componentUpdateQueue = null ;
190
204
191
- // Always set during createWorkInProgress
192
- // isReRender = false;
193
-
194
205
// These were reset above
195
206
// didScheduleRenderPhaseUpdate = false;
196
207
// renderPhaseUpdates = null;
@@ -236,9 +247,6 @@ export function resetHooks(): void {
236
247
remainingExpirationTime = NoWork ;
237
248
componentUpdateQueue = null ;
238
249
239
- // Always set during createWorkInProgress
240
- // isReRender = false;
241
-
242
250
didScheduleRenderPhaseUpdate = false ;
243
251
renderPhaseUpdates = null ;
244
252
numberOfReRenders = - 1 ;
@@ -272,7 +280,6 @@ function createWorkInProgressHook(): Hook {
272
280
if ( workInProgressHook === null ) {
273
281
// This is the first hook in the list
274
282
if ( firstWorkInProgressHook === null ) {
275
- isReRender = false ;
276
283
currentHook = firstCurrentHook ;
277
284
if ( currentHook === null ) {
278
285
// This is a newly mounted hook
@@ -284,13 +291,11 @@ function createWorkInProgressHook(): Hook {
284
291
firstWorkInProgressHook = workInProgressHook ;
285
292
} else {
286
293
// There's already a work-in-progress. Reuse it.
287
- isReRender = true ;
288
294
currentHook = firstCurrentHook ;
289
295
workInProgressHook = firstWorkInProgressHook ;
290
296
}
291
297
} else {
292
298
if ( workInProgressHook . next === null ) {
293
- isReRender = false ;
294
299
let hook ;
295
300
if ( currentHook === null ) {
296
301
// This is a newly mounted hook
@@ -309,7 +314,6 @@ function createWorkInProgressHook(): Hook {
309
314
workInProgressHook = workInProgressHook . next = hook ;
310
315
} else {
311
316
// There's already a work-in-progress. Reuse it.
312
- isReRender = true ;
313
317
workInProgressHook = workInProgressHook . next ;
314
318
currentHook = currentHook !== null ? currentHook . next : null ;
315
319
}
@@ -357,7 +361,7 @@ export function useReducer<S, A>(
357
361
let queue : UpdateQueue < S , A > | null = ( workInProgressHook . queue : any ) ;
358
362
if ( queue !== null ) {
359
363
// Already have a queue, so this is an update.
360
- if ( isReRender ) {
364
+ if ( numberOfReRenders > 0 ) {
361
365
// This is a re-render. Apply the new render phase updates to the previous
362
366
// work-in-progress hook.
363
367
const dispatch : Dispatch < A > = ( queue . dispatch : any ) ;
0 commit comments