2695
// If we're tracing updates and we've bailed out before reaching a host node,
2696
// we should fall back to recursively marking the nearest host descendants for highlight.
2697
if (traceNearestHostComponentUpdate) {
2698
- const hostFibers = findAllCurrentHostFibers(
2698
+ const hostInstances = findAllCurrentHostInstances(
2699
getFiberInstanceThrows(nextFiber),
2700
);
2701
- hostFibers.forEach(hostFiber => {
2702
- traceUpdatesForNodes.add(hostFiber.stateNode);
2701
+ hostInstances.forEach(hostInstance => {
2702
+ traceUpdatesForNodes.add(hostInstance);
2703
});
2704
}
2705
}
2943
currentRootID = -1;
2944
}
2945
2946
- function findAllCurrentHostFibers(
2946
+ function getResourceInstance(fiber: Fiber): HostInstance | null {
2947
+ if (fiber.tag === HostHoistable) {
2948
+ const resource = fiber.memoizedState;
2949
+ // Feature Detect a DOM Specific Instance of a Resource
2950
+ if (
2951
+ typeof resource === 'object' &&
2952
+ resource !== null &&
2953
+ resource.instance != null
2954
+ ) {
2955
+ return resource.instance;
2956
+ }
2957
+ }
2958
+ return null;
2959
+ }
2960
+
2961
+ function findAllCurrentHostInstances(
2962
fiberInstance: FiberInstance,
2948
- ): $ReadOnlyArray<Fiber> {
2949
- const fibers = [];
2963
+ ): $ReadOnlyArray<HostInstance> {
2964
+ const hostInstances = [];
2965
const fiber = findCurrentFiberUsingSlowPathByFiberInstance(fiberInstance);
2966
if (!fiber) {
2952
- return fibers;
2967
+ return hostInstances;
2968
}
2969
2970
// Next we'll drill down this component to find all HostComponent/Text.
2971
let node: Fiber = fiber;
2972
while (true) {
2958
- if (node.tag === HostComponent || node.tag === HostText) {
2959
- fibers.push(node);
2973
+ if (
2974
+ node.tag === HostComponent ||
2975
+ node.tag === HostText ||
2976
+ node.tag === HostSingleton ||
2977
+ node.tag === HostHoistable
2978
+ ) {
2979
+ const hostInstance = node.stateNode || getResourceInstance(node);
2980
+ if (hostInstance) {
2981
+ hostInstances.push(hostInstance);
2982
+ }
2983
} else if (node.child) {
2984
node.child.return = node;
2985
node = node.child;
2986
continue;
2987
}
2988
if (node === fiber) {
2966
- return fibers;
2989
+ return hostInstances;
2990
}
2991
while (!node.sibling) {
2992
if (!node.return || node.return === fiber) {
2970
- return fibers;
2993
+ return hostInstances;
2994
}
2995
node = node.return;
2996
}
2999
}
3000
// Flow needs the return here, but ESLint complains about it.
3001
// eslint-disable-next-line no-unreachable
2979
- return fibers;
3002
+ return hostInstances;
3003
}
3004
3005
function findHostInstancesForElementID(id: number) {
3019
return null;
3020
}
3021
2999
- const hostFibers = findAllCurrentHostFibers(devtoolsInstance);
3000
- return hostFibers.map(hostFiber => hostFiber.stateNode).filter(Boolean);
3022
+ const hostInstances = findAllCurrentHostInstances(devtoolsInstance);
3023
+ return hostInstances;
3024
} catch (err) {
3025
// The fiber might have unmounted by now.
3026
return null;