Skip to content

Commit 1be4d26

Browse files
author
Brian Vaughn
committed
Removed explicit root param and added getWorkInProgressRoot() to work loop
1 parent 15848f5 commit 1be4d26

4 files changed

Lines changed: 20 additions & 62 deletions

File tree

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ function forceUnmountCurrentAndReconcile(
277277
}
278278

279279
function updateForwardRef(
280-
root: FiberRoot,
281280
current: Fiber | null,
282281
workInProgress: Fiber,
283282
Component: any,
@@ -317,7 +316,6 @@ function updateForwardRef(
317316
nextChildren = renderWithHooks(
318317
current,
319318
workInProgress,
320-
root,
321319
render,
322320
nextProps,
323321
ref,
@@ -332,7 +330,6 @@ function updateForwardRef(
332330
nextChildren = renderWithHooks(
333331
current,
334332
workInProgress,
335-
root,
336333
render,
337334
nextProps,
338335
ref,
@@ -345,7 +342,6 @@ function updateForwardRef(
345342
nextChildren = renderWithHooks(
346343
current,
347344
workInProgress,
348-
root,
349345
render,
350346
nextProps,
351347
ref,
@@ -374,7 +370,6 @@ function updateForwardRef(
374370
}
375371

376372
function updateMemoComponent(
377-
root: FiberRoot,
378373
current: Fiber | null,
379374
workInProgress: Fiber,
380375
Component: any,
@@ -403,7 +398,6 @@ function updateMemoComponent(
403398
validateFunctionComponentInDev(workInProgress, type);
404399
}
405400
return updateSimpleMemoComponent(
406-
root,
407401
current,
408402
workInProgress,
409403
resolvedType,
@@ -484,7 +478,6 @@ function updateMemoComponent(
484478
}
485479

486480
function updateSimpleMemoComponent(
487-
root: FiberRoot,
488481
current: Fiber | null,
489482
workInProgress: Fiber,
490483
Component: any,
@@ -539,7 +532,6 @@ function updateSimpleMemoComponent(
539532
}
540533
}
541534
return updateFunctionComponent(
542-
root,
543535
current,
544536
workInProgress,
545537
Component,
@@ -609,7 +601,6 @@ function markRef(current: Fiber | null, workInProgress: Fiber) {
609601
}
610602

611603
function updateFunctionComponent(
612-
root,
613604
current,
614605
workInProgress,
615606
Component,
@@ -647,7 +638,6 @@ function updateFunctionComponent(
647638
nextChildren = renderWithHooks(
648639
current,
649640
workInProgress,
650-
root,
651641
Component,
652642
nextProps,
653643
context,
@@ -662,7 +652,6 @@ function updateFunctionComponent(
662652
nextChildren = renderWithHooks(
663653
current,
664654
workInProgress,
665-
root,
666655
Component,
667656
nextProps,
668657
context,
@@ -675,7 +664,6 @@ function updateFunctionComponent(
675664
nextChildren = renderWithHooks(
676665
current,
677666
workInProgress,
678-
root,
679667
Component,
680668
nextProps,
681669
context,
@@ -704,7 +692,6 @@ function updateFunctionComponent(
704692
}
705693

706694
function updateChunk(
707-
root: FiberRoot,
708695
current: Fiber | null,
709696
workInProgress: Fiber,
710697
chunk: any,
@@ -727,7 +714,6 @@ function updateChunk(
727714
nextChildren = renderWithHooks(
728715
current,
729716
workInProgress,
730-
root,
731717
render,
732718
nextProps,
733719
data,
@@ -742,7 +728,6 @@ function updateChunk(
742728
nextChildren = renderWithHooks(
743729
current,
744730
workInProgress,
745-
root,
746731
render,
747732
nextProps,
748733
data,
@@ -755,7 +740,6 @@ function updateChunk(
755740
nextChildren = renderWithHooks(
756741
current,
757742
workInProgress,
758-
root,
759743
render,
760744
nextProps,
761745
data,
@@ -1126,7 +1110,6 @@ function updateHostText(current, workInProgress) {
11261110
}
11271111

11281112
function mountLazyComponent(
1129-
root,
11301113
_current,
11311114
workInProgress,
11321115
elementType,
@@ -1164,7 +1147,6 @@ function mountLazyComponent(
11641147
);
11651148
}
11661149
child = updateFunctionComponent(
1167-
root,
11681150
null,
11691151
workInProgress,
11701152
Component,
@@ -1195,7 +1177,6 @@ function mountLazyComponent(
11951177
);
11961178
}
11971179
child = updateForwardRef(
1198-
root,
11991180
null,
12001181
workInProgress,
12011182
Component,
@@ -1220,7 +1201,6 @@ function mountLazyComponent(
12201201
}
12211202
}
12221203
child = updateMemoComponent(
1223-
root,
12241204
null,
12251205
workInProgress,
12261206
Component,
@@ -1234,7 +1214,6 @@ function mountLazyComponent(
12341214
if (enableChunksAPI) {
12351215
// TODO: Resolve for Hot Reloading.
12361216
child = updateChunk(
1237-
root,
12381217
null,
12391218
workInProgress,
12401219
Component,
@@ -1327,7 +1306,6 @@ function mountIncompleteClassComponent(
13271306
}
13281307

13291308
function mountIndeterminateComponent(
1330-
root,
13311309
_current,
13321310
workInProgress,
13331311
Component,
@@ -1384,7 +1362,6 @@ function mountIndeterminateComponent(
13841362
value = renderWithHooks(
13851363
null,
13861364
workInProgress,
1387-
root,
13881365
Component,
13891366
props,
13901367
context,
@@ -1394,7 +1371,6 @@ function mountIndeterminateComponent(
13941371
value = renderWithHooks(
13951372
null,
13961373
workInProgress,
1397-
root,
13981374
Component,
13991375
props,
14001376
context,
@@ -1491,7 +1467,6 @@ function mountIndeterminateComponent(
14911467
value = renderWithHooks(
14921468
null,
14931469
workInProgress,
1494-
root,
14951470
Component,
14961471
props,
14971472
context,
@@ -2911,7 +2886,6 @@ function remountFiber(
29112886
}
29122887

29132888
function beginWork(
2914-
root: FiberRoot,
29152889
current: Fiber | null,
29162890
workInProgress: Fiber,
29172891
renderExpirationTime: ExpirationTime,
@@ -3135,7 +3109,6 @@ function beginWork(
31353109
switch (workInProgress.tag) {
31363110
case IndeterminateComponent: {
31373111
return mountIndeterminateComponent(
3138-
root,
31393112
current,
31403113
workInProgress,
31413114
workInProgress.type,
@@ -3145,7 +3118,6 @@ function beginWork(
31453118
case LazyComponent: {
31463119
const elementType = workInProgress.elementType;
31473120
return mountLazyComponent(
3148-
root,
31493121
current,
31503122
workInProgress,
31513123
elementType,
@@ -3161,7 +3133,6 @@ function beginWork(
31613133
? unresolvedProps
31623134
: resolveDefaultProps(Component, unresolvedProps);
31633135
return updateFunctionComponent(
3164-
root,
31653136
current,
31663137
workInProgress,
31673138
Component,
@@ -3210,7 +3181,6 @@ function beginWork(
32103181
? unresolvedProps
32113182
: resolveDefaultProps(type, unresolvedProps);
32123183
return updateForwardRef(
3213-
root,
32143184
current,
32153185
workInProgress,
32163186
type,
@@ -3257,7 +3227,6 @@ function beginWork(
32573227
}
32583228
resolvedProps = resolveDefaultProps(type.type, resolvedProps);
32593229
return updateMemoComponent(
3260-
root,
32613230
current,
32623231
workInProgress,
32633232
type,
@@ -3268,7 +3237,6 @@ function beginWork(
32683237
}
32693238
case SimpleMemoComponent: {
32703239
return updateSimpleMemoComponent(
3271-
root,
32723240
current,
32733241
workInProgress,
32743242
workInProgress.type,
@@ -3324,7 +3292,6 @@ function beginWork(
33243292
const chunk = workInProgress.type;
33253293
const props = workInProgress.pendingProps;
33263294
return updateChunk(
3327-
root,
33283295
current,
33293296
workInProgress,
33303297
chunk,

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import type {
1515
ReactEventResponderListener,
1616
} from 'shared/ReactTypes';
1717
import type {Fiber} from './ReactFiber';
18-
import type {FiberRoot} from './ReactFiberRoot';
1918
import type {ExpirationTime} from './ReactFiberExpirationTime';
2019
import type {HookEffectTag} from './ReactHookEffectTags';
2120
import type {SuspenseConfig} from './ReactFiberSuspenseConfig';
2221
import type {ReactPriorityLevel} from './SchedulerWithReactIntegration';
22+
import type {FiberRoot} from './ReactFiberRoot';
2323

2424
import ReactSharedInternals from 'shared/ReactSharedInternals';
2525

@@ -36,6 +36,7 @@ import {
3636
Passive as HookPassive,
3737
} from './ReactHookEffectTags';
3838
import {
39+
getWorkInProgressRoot,
3940
scheduleUpdateOnFiber,
4041
computeExpirationForFiber,
4142
requestCurrentTimeForUpdate,
@@ -181,10 +182,6 @@ let renderExpirationTime: ExpirationTime = NoWork;
181182
// the work-in-progress hook.
182183
let currentlyRenderingFiber: Fiber = (null: any);
183184

184-
// The work-in-progress root fiber.
185-
// Used by mutable source hook to detect tears from pending updates.
186-
let currentlyRenderingRoot: FiberRoot = (null: any);
187-
188185
// Hooks are stored as a linked list on the fiber's memoizedState field. The
189186
// current hook list is the list that belongs to the current fiber. The
190187
// work-in-progress hook list is a new list that will be added to the
@@ -363,15 +360,13 @@ function areHookInputsEqual(
363360
export function renderWithHooks(
364361
current: Fiber | null,
365362
workInProgress: Fiber,
366-
root: FiberRoot,
367363
Component: any,
368364
props: any,
369365
secondArg: any,
370366
nextRenderExpirationTime: ExpirationTime,
371367
): any {
372368
renderExpirationTime = nextRenderExpirationTime;
373369
currentlyRenderingFiber = workInProgress;
374-
currentlyRenderingRoot = root;
375370

376371
if (__DEV__) {
377372
hookTypesDev =
@@ -478,7 +473,6 @@ export function renderWithHooks(
478473

479474
renderExpirationTime = NoWork;
480475
currentlyRenderingFiber = (null: any);
481-
currentlyRenderingRoot = (null: any);
482476

483477
currentHook = null;
484478
workInProgressHook = null;
@@ -873,11 +867,15 @@ function useMutableSourceImpl<Source, Snapshot>(
873867
): Snapshot {
874868
const {getSnapshot, subscribe} = config;
875869
const version = source._getVersion();
876-
const pendingExpirationTime = getPendingExpirationTime(
877-
currentlyRenderingRoot,
878-
source,
870+
const root = ((getWorkInProgressRoot(): any): FiberRoot);
871+
872+
invariant(
873+
root !== null,
874+
'Expected a work-in-progress root. This is likely a bug in React. Please file an issue.',
879875
);
880876

877+
const pendingExpirationTime = getPendingExpirationTime(root, source);
878+
881879
// Is it safe to read from this source during the current render?
882880
let isSafeToReadFromSource = false;
883881

@@ -957,7 +955,6 @@ function useMutableSourceImpl<Source, Snapshot>(
957955

958956
if (prevSource !== source) {
959957
const fiber = currentlyRenderingFiber;
960-
const root = currentlyRenderingRoot;
961958

962959
const create = () => {
963960
const scheduleUpdate = () => {

0 commit comments

Comments
 (0)