Skip to content

Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement)#57468

Closed
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D110888634
Closed

Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement)#57468
rubennorte wants to merge 1 commit into
react:mainfrom
rubennorte:export-D110888634

Conversation

@rubennorte

@rubennorte rubennorte commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary:
Removes the ensureInstance(ref.current, ReactNativeElement) pattern from Fantom tests. Host refs are typed as HostInstance and read with nullthrows(ref.current); component-specific instance types (e.g. React.ElementRef<typeof TextInput>, React.ElementRef<typeof ScrollView>) are kept only where a test actually uses a component's imperative API (focus/blur/clear, getInnerViewRef, etc.). This drops the ReactNativeElement/ensureInstance imports from tests that only needed a non-null host instance.

Where a test genuinely needs a runtime type check, instanceof ReactNativeElement / toBeInstanceOf(ReactNativeElement) is replaced with the standard instanceof HTMLElement (a global), since React Native elements are instances of HTMLElement at runtime.

This also covers the internal -itest.fb.js tests and the shared ShadowNode test utilities (ShadowNodeReferenceCounter/ShadowNodeRevisionGetter), which now type their refs as HostInstance.

Known follow-up: the RN Flow global type definitions still need to be fixed. At the type level HTMLElement does not match HostInstance yet, even though the runtime values do. Because of this, HTMLElement cannot be used where a narrowed value flows into RN-internal APIs typed as HostInstance/ReadOnlyNode (e.g. VirtualView, which instead types its helper params as HostInstance directly and passes them through without a narrowing check). Aligning the HTMLElement global definition with HostInstance would let those remaining spots use HTMLElement too.

This is a test-only change with no runtime or user-facing impact.

Changelog:
[Internal]

Differential Revision: D110888634

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jul 7, 2026
@meta-codesync

meta-codesync Bot commented Jul 7, 2026

Copy link
Copy Markdown

@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110888634.

@meta-codesync meta-codesync Bot changed the title Simplify Fantom test element refs to React.ElementRef + nullthrows Simplify Fantom test element refs to React.ElementRef + nullthrows (#57468) Jul 7, 2026
rubennorte added a commit to rubennorte/react-native that referenced this pull request Jul 7, 2026
…eact#57468)

Summary:

Refactors Fantom `-itest.js` tests to type host refs as `React.ElementRef<typeof Component>` and read them with `nullthrows(ref.current)`, replacing the `ensureInstance(ref.current, ReactNativeElement)` pattern. Non-null element values are typed as `HostInstance`. This removes the `ReactNativeElement` (and `ensureInstance`) imports from tests that only needed a non-null host instance.

Where a test genuinely needs a runtime type check, `instanceof ReactNativeElement` / `toBeInstanceOf(ReactNativeElement)` is replaced with the standard `instanceof HTMLElement` (a global), since React Native elements are instances of `HTMLElement` at runtime.

Known follow-up: the RN Flow global type definitions still need to be fixed. At the type level `HTMLElement` does not match `HostInstance` yet, even though the runtime values do. Because of this, `HTMLElement` cannot be used where a narrowed value flows into RN-internal APIs typed as `HostInstance`/`ReadOnlyNode` (e.g. `VirtualView`, which instead types its helper params as `HostInstance` directly and passes them through without a narrowing check). Aligning the `HTMLElement` global definition with `HostInstance` would let those remaining spots use `HTMLElement` too.

This is a test-only change with no runtime or user-facing impact.

Changelog:
[Internal]

Differential Revision: D110888634
@rubennorte rubennorte force-pushed the export-D110888634 branch from 27a4f9c to c88e284 Compare July 7, 2026 18:21
…HTMLElement)

Summary:
Removes the `ensureInstance(ref.current, ReactNativeElement)` pattern from Fantom tests. Host refs are typed as `HostInstance` and read with `nullthrows(ref.current)`; component-specific instance types (e.g. `React.ElementRef<typeof TextInput>`, `React.ElementRef<typeof ScrollView>`) are kept only where a test actually uses a component's imperative API (`focus`/`blur`/`clear`, `getInnerViewRef`, etc.). This drops the `ReactNativeElement`/`ensureInstance` imports from tests that only needed a non-null host instance.

Where a test genuinely needs a runtime type check, `instanceof ReactNativeElement` / `toBeInstanceOf(ReactNativeElement)` is replaced with the standard `instanceof HTMLElement` (a global), since React Native elements are instances of `HTMLElement` at runtime.

This also covers the internal `-itest.fb.js` tests and the shared ShadowNode test utilities (`ShadowNodeReferenceCounter`/`ShadowNodeRevisionGetter`), which now type their refs as `HostInstance`.

Known follow-up: the RN Flow global type definitions still need to be fixed. At the type level `HTMLElement` does not match `HostInstance` yet, even though the runtime values do. Because of this, `HTMLElement` cannot be used where a narrowed value flows into RN-internal APIs typed as `HostInstance`/`ReadOnlyNode` (e.g. `VirtualView`, which instead types its helper params as `HostInstance` directly and passes them through without a narrowing check). Aligning the `HTMLElement` global definition with `HostInstance` would let those remaining spots use `HTMLElement` too.

This is a test-only change with no runtime or user-facing impact.

Changelog:
[Internal]

Differential Revision: D110888634
@meta-codesync meta-codesync Bot changed the title Simplify Fantom test element refs to React.ElementRef + nullthrows (#57468) Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement) Jul 7, 2026
@rubennorte rubennorte force-pushed the export-D110888634 branch from c88e284 to f77a89d Compare July 7, 2026 18:29
@meta-codesync meta-codesync Bot closed this in 5e64e90 Jul 8, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 8, 2026
@meta-codesync

meta-codesync Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been merged in 5e64e90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant