Skip to content

Commit a57f3dd

Browse files
committed
Make Instance type generic
1 parent 5f155a2 commit a57f3dd

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ function addEventListenerToChild(
26492649
listener: EventListener,
26502650
optionsOrUseCapture?: EventListenerOptionsOrUseCapture,
26512651
): boolean {
2652-
const instance = getInstanceFromHostFiber(child);
2652+
const instance = getInstanceFromHostFiber<Instance>(child);
26532653
instance.addEventListener(type, listener, optionsOrUseCapture);
26542654
return false;
26552655
}
@@ -2689,7 +2689,7 @@ function removeEventListenerFromChild(
26892689
listener: EventListener,
26902690
optionsOrUseCapture?: EventListenerOptionsOrUseCapture,
26912691
): boolean {
2692-
const instance = getInstanceFromHostFiber(child);
2692+
const instance = getInstanceFromHostFiber<Instance>(child);
26932693
instance.removeEventListener(type, listener, optionsOrUseCapture);
26942694
return false;
26952695
}
@@ -2708,7 +2708,7 @@ function setFocusOnFiberIfFocusable(
27082708
fiber: Fiber,
27092709
focusOptions?: FocusOptions,
27102710
): boolean {
2711-
const instance = getInstanceFromHostFiber(fiber);
2711+
const instance = getInstanceFromHostFiber<Instance>(fiber);
27122712
return setFocusIfFocusable(instance, focusOptions);
27132713
}
27142714
// $FlowFixMe[prop-missing]
@@ -2740,7 +2740,7 @@ FragmentInstance.prototype.blur = function (this: FragmentInstanceType): void {
27402740
};
27412741
function blurActiveElementWithinFragment(child: Fiber): boolean {
27422742
// TODO: We can get the activeElement from the parent outside of the loop when we have a reference.
2743-
const instance = getInstanceFromHostFiber(child);
2743+
const instance = getInstanceFromHostFiber<Instance>(child);
27442744
const ownerDocument = instance.ownerDocument;
27452745
if (instance === ownerDocument.activeElement) {
27462746
// $FlowFixMe[prop-missing]
@@ -2764,7 +2764,7 @@ function observeChild(
27642764
child: Fiber,
27652765
observer: IntersectionObserver | ResizeObserver,
27662766
) {
2767-
const instance = getInstanceFromHostFiber(child);
2767+
const instance = getInstanceFromHostFiber<Instance>(child);
27682768
observer.observe(instance);
27692769
return false;
27702770
}
@@ -2789,7 +2789,7 @@ function unobserveChild(
27892789
child: Fiber,
27902790
observer: IntersectionObserver | ResizeObserver,
27912791
) {
2792-
const instance = getInstanceFromHostFiber(child);
2792+
const instance = getInstanceFromHostFiber<Instance>(child);
27932793
observer.unobserve(instance);
27942794
return false;
27952795
}
@@ -2802,7 +2802,7 @@ FragmentInstance.prototype.getClientRects = function (
28022802
return rects;
28032803
};
28042804
function collectClientRects(child: Fiber, rects: Array<DOMRect>): boolean {
2805-
const instance = getInstanceFromHostFiber(child);
2805+
const instance = getInstanceFromHostFiber<Instance>(child);
28062806
// $FlowFixMe[method-unbinding]
28072807
rects.push.apply(rects, instance.getClientRects());
28082808
return false;
@@ -2816,7 +2816,8 @@ FragmentInstance.prototype.getRootNode = function (
28162816
if (parentHostFiber === null) {
28172817
return this;
28182818
}
2819-
const parentHostInstance = getInstanceFromHostFiber(parentHostFiber);
2819+
const parentHostInstance =
2820+
getInstanceFromHostFiber<Instance>(parentHostFiber);
28202821
const rootNode =
28212822
// $FlowFixMe[incompatible-cast] Flow expects Node
28222823
(parentHostInstance.getRootNode(getRootNodeOptions): Document | ShadowRoot);
@@ -2838,7 +2839,8 @@ FragmentInstance.prototype.compareDocumentPosition = function (
28382839
if (children.length === 0) {
28392840
// If the fragment has no children, we can use the parent and
28402841
// siblings to determine a position.
2841-
const parentHostInstance = getInstanceFromHostFiber(parentHostFiber);
2842+
const parentHostInstance =
2843+
getInstanceFromHostFiber<Instance>(parentHostFiber);
28422844
const parentResult = parentHostInstance.compareDocumentPosition(otherNode);
28432845
result = parentResult;
28442846
if (parentHostInstance === otherNode) {
@@ -2852,7 +2854,7 @@ FragmentInstance.prototype.compareDocumentPosition = function (
28522854
result = Node.DOCUMENT_POSITION_PRECEDING;
28532855
} else {
28542856
const nextSiblingInstance =
2855-
getInstanceFromHostFiber(nextSiblingFiber);
2857+
getInstanceFromHostFiber<Instance>(nextSiblingFiber);
28562858
const nextSiblingResult =
28572859
nextSiblingInstance.compareDocumentPosition(otherNode);
28582860
if (
@@ -2871,8 +2873,10 @@ FragmentInstance.prototype.compareDocumentPosition = function (
28712873
return result;
28722874
}
28732875

2874-
const firstElement = getInstanceFromHostFiber(children[0]);
2875-
const lastElement = getInstanceFromHostFiber(children[children.length - 1]);
2876+
const firstElement = getInstanceFromHostFiber<Instance>(children[0]);
2877+
const lastElement = getInstanceFromHostFiber<Instance>(
2878+
children[children.length - 1],
2879+
);
28762880
const firstResult = firstElement.compareDocumentPosition(otherNode);
28772881
const lastResult = lastElement.compareDocumentPosition(otherNode);
28782882
if (

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ FragmentInstance.prototype.observeUsing = function (
644644
traverseFragmentInstance(this._fragmentFiber, observeChild, observer);
645645
};
646646
function observeChild(child: Fiber, observer: IntersectionObserver) {
647-
const instance = getInstanceFromHostFiber(child);
647+
const instance = getInstanceFromHostFiber<Instance>(child);
648648
const publicInstance = getPublicInstance(instance);
649649
if (publicInstance == null) {
650650
throw new Error('Expected to find a host node. This is a bug in React.');
@@ -671,7 +671,7 @@ FragmentInstance.prototype.unobserveUsing = function (
671671
}
672672
};
673673
function unobserveChild(child: Fiber, observer: IntersectionObserver) {
674-
const instance = getInstanceFromHostFiber(child);
674+
const instance = getInstanceFromHostFiber<Instance>(child);
675675
const publicInstance = getPublicInstance(instance);
676676
if (publicInstance == null) {
677677
throw new Error('Expected to find a host node. This is a bug in React.');

packages/react-reconciler/src/ReactFiberTreeReflection.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
Container,
1313
ActivityInstance,
1414
SuspenseInstance,
15-
Instance,
1615
} from './ReactFiberConfig';
1716
import type {ActivityState} from './ReactFiberActivityComponent';
1817
import type {SuspenseState} from './ReactFiberSuspenseComponent';
@@ -411,7 +410,7 @@ export function getFragmentParentHostFiber(fiber: Fiber): null | Fiber {
411410
return null;
412411
}
413412

414-
export function getInstanceFromHostFiber(fiber: Fiber): Instance {
413+
export function getInstanceFromHostFiber<I>(fiber: Fiber): I {
415414
switch (fiber.tag) {
416415
case HostComponent:
417416
return fiber.stateNode;

0 commit comments

Comments
 (0)