Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up enableDOMDocumentAPI feature flag #49990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-native-fantom/runner/getFantomTestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default function getFantomTestConfig(
common: {},
jsOnly: {
enableAccessToHostTreeInFabric: true,
enableDOMDocumentAPI: true,
},
reactInternal: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ function getReadOnlyTextClass(): Class<ReadOnlyTextT> {
}

export function createPublicRootInstance(rootTag: RootTag): PublicRootInstance {
if (
ReactNativeFeatureFlags.enableAccessToHostTreeInFabric() &&
ReactNativeFeatureFlags.enableDOMDocumentAPI()
) {
if (ReactNativeFeatureFlags.enableAccessToHostTreeInFabric()) {
const ReactNativeDocumentModule = getReactNativeDocumentModule();

// $FlowExpectedError[incompatible-return]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,18 +540,6 @@ const definitions: FeatureFlagDefinitions = {
},
ossReleaseStage: 'none',
},
enableDOMDocumentAPI: {
defaultValue: false,
metadata: {
dateAdded: '2025-01-28',
description:
'Enables the DOM Document API, exposing instaces of document through `getRootNode` and `ownerDocument`, and providing access to the `documentElement` representing the root node. ' +
'This flag will be short-lived, only to test the Document API specifically, and then it will be collapsed into the enableAccessToHostTreeInFabric flag.',
expectedReleaseValue: true,
purpose: 'experimentation',
},
ossReleaseStage: 'none',
},
fixVirtualizeListCollapseWindowSize: {
defaultValue: false,
metadata: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4f1befe0cec24eeb531d7ecca6bc451b>>
* @generated SignedSource<<bda96f04a2464d7b8a2eee8b4c2e216f>>
* @flow strict
*/

Expand Down Expand Up @@ -33,7 +33,6 @@ export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{
avoidStateUpdateInAnimatedPropsMemo: Getter<boolean>,
disableInteractionManager: Getter<boolean>,
enableAccessToHostTreeInFabric: Getter<boolean>,
enableDOMDocumentAPI: Getter<boolean>,
fixVirtualizeListCollapseWindowSize: Getter<boolean>,
isLayoutAnimationEnabled: Getter<boolean>,
scheduleAnimatedCleanupInMicrotask: Getter<boolean>,
Expand Down Expand Up @@ -121,11 +120,6 @@ export const disableInteractionManager: Getter<boolean> = createJavaScriptFlagGe
*/
export const enableAccessToHostTreeInFabric: Getter<boolean> = createJavaScriptFlagGetter('enableAccessToHostTreeInFabric', false);

/**
* Enables the DOM Document API, exposing instaces of document through `getRootNode` and `ownerDocument`, and providing access to the `documentElement` representing the root node. This flag will be short-lived, only to test the Document API specifically, and then it will be collapsed into the enableAccessToHostTreeInFabric flag.
*/
export const enableDOMDocumentAPI: Getter<boolean> = createJavaScriptFlagGetter('enableDOMDocumentAPI', false);

/**
* Fixing an edge case where the current window size is not properly calculated with fast scrolling. Window size collapsed to 1 element even if windowSize more than the current amount of elements
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,12 @@ export default class ReadOnlyNode {
}

getRootNode(): ReadOnlyNode {
if (ReactNativeFeatureFlags.enableDOMDocumentAPI()) {
if (this.isConnected) {
// If this is the document node, then the root node is itself.
return this.ownerDocument ?? this;
}

return this;
} else {
// eslint-disable-next-line consistent-this
let lastKnownParent: ReadOnlyNode = this;
let nextPossibleParent: ?ReadOnlyNode = this.parentNode;

while (nextPossibleParent != null) {
lastKnownParent = nextPossibleParent;
nextPossibleParent = nextPossibleParent.parentNode;
}

return lastKnownParent;
if (this.isConnected) {
// If this is the document node, then the root node is itself.
return this.ownerDocument ?? this;
}

return this;
}

hasChildNodes(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('ReactNativeElement', () => {
describe('getRootNode()', () => {
// This is the desired implementation (not implemented yet).
// eslint-disable-next-line jest/no-disabled-tests
it.skip('returns a root node representing the document', () => {
it('returns a root node representing the document', () => {
let lastParentANode;
let lastParentBNode;
let lastChildANode;
Expand Down Expand Up @@ -327,120 +327,6 @@ describe('ReactNativeElement', () => {
expect(parentBNode.getRootNode()).toBe(parentBNode);
expect(childBNode.getRootNode()).toBe(childBNode);
});

// This is the current (incorrect) behavior.
// TODO: fix this implementation and "unskip" the previous test.
it('returns the highest parent in the hierarchy', () => {
let lastParentNode;
let lastChildNode;
let lastGrandChildNode;

const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(
<View
key="parent"
ref={node => {
lastParentNode = node;
}}>
<View
key="child"
ref={node => {
lastChildNode = node;
}}>
<View
key="grandchild"
ref={node => {
lastGrandChildNode = node;
}}
/>
</View>
</View>,
);
});

const parentNode = ensureReactNativeElement(lastParentNode);
const childNode = ensureReactNativeElement(lastChildNode);
const grandChildNode = ensureReactNativeElement(lastGrandChildNode);

expect(parentNode.getRootNode()).toBe(parentNode);
expect(childNode.getRootNode()).toBe(parentNode);
expect(grandChildNode.getRootNode()).toBe(parentNode);

// Remove the grandchild
Fantom.runTask(() => {
root.render(
<View key="parent">
<View key="child" />
</View>,
);
});

expect(parentNode.getRootNode()).toBe(parentNode);
expect(childNode.getRootNode()).toBe(parentNode);

// The root node of a disconnected node is itself
expect(grandChildNode.getRootNode()).toBe(grandChildNode);

// Unmount node
Fantom.runTask(() => {
root.render(<></>);
});

// The root node of a disconnected node is itself
expect(parentNode.getRootNode()).toBe(parentNode);
expect(childNode.getRootNode()).toBe(childNode);
expect(grandChildNode.getRootNode()).toBe(grandChildNode);
});

// This is the current (incorrect) behavior.
// TODO: fix this implementation and "unskip" the previous test.
it('returns the highest parent in the hierarchy (multiple root views)', () => {
let lastParentANode;
let lastParentBNode;
let lastChildANode;
let lastChildBNode;

const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(
<>
<View
key="parentA"
ref={node => {
lastParentANode = node;
}}>
<View
key="childA"
ref={node => {
lastChildANode = node;
}}
/>
</View>
<View
key="parentB"
ref={node => {
lastParentBNode = node;
}}>
<View
key="childB"
ref={node => {
lastChildBNode = node;
}}
/>
</View>
</>,
);
});

const parentANode = ensureReactNativeElement(lastParentANode);
const childANode = ensureReactNativeElement(lastChildANode);
const parentBNode = ensureReactNativeElement(lastParentBNode);
const childBNode = ensureReactNativeElement(lastChildBNode);

expect(childANode.getRootNode()).toBe(parentANode);
expect(childBNode.getRootNode()).toBe(parentBNode);
});
});

describe('firstChild / lastChild / previousSibling / nextSibling / parentNode / parentElement', () => {
Expand Down
Loading
Loading