Skip to content

Commit a3c5b1f

Browse files
authored
[Fresh] Rename findHostNodesForHotUpdate to findHostInstancesForHotUpdate (#15904)
1 parent 7985bf7 commit a3c5b1f

File tree

3 files changed

+53
-39
lines changed

3 files changed

+53
-39
lines changed

packages/react-reconciler/src/ReactFiberHotReloading.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -292,26 +292,30 @@ function scheduleFibersWithFamiliesRecursively(
292292
}
293293
}
294294

295-
export function findHostNodesForHotUpdate(
295+
export function findHostInstancesForHotUpdate(
296296
root: FiberRoot,
297297
families: Array<Family>,
298298
): Set<Instance> {
299299
if (__DEV__) {
300-
const hostNodes = new Set();
300+
const hostInstances = new Set();
301301
const types = new Set(families.map(family => family.current));
302-
findHostNodesForMatchingFibersRecursively(root.current, types, hostNodes);
303-
return hostNodes;
302+
findHostInstancesForMatchingFibersRecursively(
303+
root.current,
304+
types,
305+
hostInstances,
306+
);
307+
return hostInstances;
304308
} else {
305309
throw new Error(
306-
'Did not expect findHostNodesForHotUpdate to be called in production.',
310+
'Did not expect findHostInstancesForHotUpdate to be called in production.',
307311
);
308312
}
309313
}
310314

311-
function findHostNodesForMatchingFibersRecursively(
315+
function findHostInstancesForMatchingFibersRecursively(
312316
fiber: Fiber,
313317
types: Set<any>,
314-
hostNodes: Set<Instance>,
318+
hostInstances: Set<Instance>,
315319
) {
316320
if (__DEV__) {
317321
const {child, sibling, tag, type} = fiber;
@@ -341,44 +345,52 @@ function findHostNodesForMatchingFibersRecursively(
341345
// We have a match. This only drills down to the closest host components.
342346
// There's no need to search deeper because for the purpose of giving
343347
// visual feedback, "flashing" outermost parent rectangles is sufficient.
344-
findHostNodesForFiberShallowly(fiber, hostNodes);
348+
findHostInstancesForFiberShallowly(fiber, hostInstances);
345349
} else {
346350
// If there's no match, maybe there will be one further down in the child tree.
347351
if (child !== null) {
348-
findHostNodesForMatchingFibersRecursively(child, types, hostNodes);
352+
findHostInstancesForMatchingFibersRecursively(
353+
child,
354+
types,
355+
hostInstances,
356+
);
349357
}
350358
}
351359

352360
if (sibling !== null) {
353-
findHostNodesForMatchingFibersRecursively(sibling, types, hostNodes);
361+
findHostInstancesForMatchingFibersRecursively(
362+
sibling,
363+
types,
364+
hostInstances,
365+
);
354366
}
355367
}
356368
}
357369

358-
function findHostNodesForFiberShallowly(
370+
function findHostInstancesForFiberShallowly(
359371
fiber: Fiber,
360-
hostNodes: Set<Instance>,
372+
hostInstances: Set<Instance>,
361373
): void {
362374
if (__DEV__) {
363-
const foundHostNodes = findChildHostNodesForFiberShallowly(
375+
const foundHostInstances = findChildHostInstancesForFiberShallowly(
364376
fiber,
365-
hostNodes,
377+
hostInstances,
366378
);
367-
if (foundHostNodes) {
379+
if (foundHostInstances) {
368380
return;
369381
}
370382
// If we didn't find any host children, fallback to closest host parent.
371383
let node = fiber;
372384
while (true) {
373385
switch (node.tag) {
374386
case HostComponent:
375-
hostNodes.add(node.stateNode);
387+
hostInstances.add(node.stateNode);
376388
return;
377389
case HostPortal:
378-
hostNodes.add(node.stateNode.containerInfo);
390+
hostInstances.add(node.stateNode.containerInfo);
379391
return;
380392
case HostRoot:
381-
hostNodes.add(node.stateNode.containerInfo);
393+
hostInstances.add(node.stateNode.containerInfo);
382394
return;
383395
}
384396
if (node.return === null) {
@@ -389,30 +401,30 @@ function findHostNodesForFiberShallowly(
389401
}
390402
}
391403

392-
function findChildHostNodesForFiberShallowly(
404+
function findChildHostInstancesForFiberShallowly(
393405
fiber: Fiber,
394-
hostNodes: Set<Instance>,
406+
hostInstances: Set<Instance>,
395407
): boolean {
396408
if (__DEV__) {
397409
let node: Fiber = fiber;
398-
let foundHostNodes = false;
410+
let foundHostInstances = false;
399411
while (true) {
400412
if (node.tag === HostComponent) {
401413
// We got a match.
402-
foundHostNodes = true;
403-
hostNodes.add(node.stateNode);
414+
foundHostInstances = true;
415+
hostInstances.add(node.stateNode);
404416
// There may still be more, so keep searching.
405417
} else if (node.child !== null) {
406418
node.child.return = node;
407419
node = node.child;
408420
continue;
409421
}
410422
if (node === fiber) {
411-
return foundHostNodes;
423+
return foundHostInstances;
412424
}
413425
while (node.sibling === null) {
414426
if (node.return === null || node.return === fiber) {
415-
return foundHostNodes;
427+
return foundHostInstances;
416428
}
417429
node = node.return;
418430
}

packages/react-reconciler/src/ReactFiberReconciler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {revertPassiveEffectsChange} from 'shared/ReactFeatureFlags';
7272
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
7373
import {
7474
scheduleHotUpdate,
75-
findHostNodesForHotUpdate,
75+
findHostInstancesForHotUpdate,
7676
} from './ReactFiberHotReloading';
7777

7878
type OpaqueRoot = FiberRoot;
@@ -475,7 +475,9 @@ export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {
475475

476476
return injectInternals({
477477
...devToolsConfig,
478-
findHostNodesForHotUpdate: __DEV__ ? findHostNodesForHotUpdate : null,
478+
findHostInstancesForHotUpdate: __DEV__
479+
? findHostInstancesForHotUpdate
480+
: null,
479481
scheduleHotUpdate: __DEV__ ? scheduleHotUpdate : null,
480482
overrideHookState,
481483
overrideProps,

packages/react-refresh/src/__tests__/ReactFresh-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ let act;
2020
describe('ReactFresh', () => {
2121
let container;
2222
let lastRoot;
23-
let findHostNodesForHotUpdate;
23+
let findHostInstancesForHotUpdate;
2424
let scheduleHotUpdate;
2525

2626
beforeEach(() => {
2727
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
2828
supportsFiber: true,
2929
inject: injected => {
3030
scheduleHotUpdate = injected.scheduleHotUpdate;
31-
findHostNodesForHotUpdate = injected.findHostNodesForHotUpdate;
31+
findHostInstancesForHotUpdate = injected.findHostInstancesForHotUpdate;
3232
},
3333
onCommitFiberRoot: (id, root) => {
3434
lastRoot = root;
@@ -2937,7 +2937,7 @@ describe('ReactFresh', () => {
29372937
}
29382938
});
29392939

2940-
it('can find host nodes for a family', () => {
2940+
it('can find host instances for a family', () => {
29412941
if (__DEV__) {
29422942
render(() => {
29432943
function Child({children}) {
@@ -3010,37 +3010,37 @@ describe('ReactFresh', () => {
30103010
const childFamily = ReactFreshRuntime.getFamilyByID('Child');
30113011
const emptyFamily = ReactFreshRuntime.getFamilyByID('Empty');
30123012

3013-
testFindNodesForFamilies(
3013+
testFindHostInstancesForFamilies(
30143014
[parentFamily],
30153015
container.querySelectorAll('.Parent'),
30163016
);
30173017

3018-
testFindNodesForFamilies(
3018+
testFindHostInstancesForFamilies(
30193019
[childFamily],
30203020
container.querySelectorAll('.Child'),
30213021
);
30223022

30233023
// When searching for both Parent and Child,
30243024
// we'll stop visual highlighting at the Parent.
3025-
testFindNodesForFamilies(
3025+
testFindHostInstancesForFamilies(
30263026
[parentFamily, childFamily],
30273027
container.querySelectorAll('.Parent'),
30283028
);
30293029

30303030
// When we can't find host nodes, use the closest parent.
3031-
testFindNodesForFamilies(
3031+
testFindHostInstancesForFamilies(
30323032
[emptyFamily],
30333033
container.querySelectorAll('.App'),
30343034
);
30353035
}
30363036
});
30373037

3038-
function testFindNodesForFamilies(families, expectedNodes) {
3039-
const foundNodes = Array.from(
3040-
findHostNodesForHotUpdate(lastRoot, families),
3038+
function testFindHostInstancesForFamilies(families, expectedNodes) {
3039+
const foundInstances = Array.from(
3040+
findHostInstancesForHotUpdate(lastRoot, families),
30413041
);
3042-
expect(foundNodes.length).toEqual(expectedNodes.length);
3043-
foundNodes.forEach((node, i) => {
3042+
expect(foundInstances.length).toEqual(expectedNodes.length);
3043+
foundInstances.forEach((node, i) => {
30443044
expect(node).toBe(expectedNodes[i]);
30453045
});
30463046
}

0 commit comments

Comments
 (0)