Add getRootNode to fabric fragment instance (#34544)

Stacked on #34533 for root fragment handling

This is the same approach as DOM, where we call getRootNode on the
parent.
    
Tests are in react-native using Fantom.
This commit is contained in:
Jack Pope 2025-10-03 09:48:37 -04:00 committed by GitHub
parent 19f65ff179
commit e866b1d1e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -645,6 +645,9 @@ export type FragmentInstanceType = {
observeUsing: (observer: IntersectionObserver) => void, observeUsing: (observer: IntersectionObserver) => void,
unobserveUsing: (observer: IntersectionObserver) => void, unobserveUsing: (observer: IntersectionObserver) => void,
compareDocumentPosition: (otherNode: PublicInstance) => number, compareDocumentPosition: (otherNode: PublicInstance) => number,
getRootNode(getRootNodeOptions?: {
composed: boolean,
}): Node | FragmentInstanceType,
}; };
function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) { function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) {
@ -754,6 +757,21 @@ function collectChildren(child: Fiber, collection: Array<Fiber>): boolean {
return false; return false;
} }
// $FlowFixMe[prop-missing]
FragmentInstance.prototype.getRootNode = function (
this: FragmentInstanceType,
getRootNodeOptions?: {composed: boolean},
): Node | FragmentInstanceType {
const parentHostFiber = getFragmentParentHostFiber(this._fragmentFiber);
if (parentHostFiber === null) {
return this;
}
const parentHostInstance = getPublicInstanceFromHostFiber(parentHostFiber);
// $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
const rootNode = (parentHostInstance.getRootNode(getRootNodeOptions): Node);
return rootNode;
};
export function createFragmentInstance( export function createFragmentInstance(
fragmentFiber: Fiber, fragmentFiber: Fiber,
): FragmentInstanceType { ): FragmentInstanceType {