Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement)#57468
Closed
rubennorte wants to merge 1 commit into
Closed
Remove ReactNativeElement from Fantom tests (nullthrows/HostInstance/HTMLElement)#57468rubennorte wants to merge 1 commit into
rubennorte wants to merge 1 commit into
Conversation
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110888634. |
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
27a4f9c to
c88e284
Compare
…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
c88e284 to
f77a89d
Compare
|
This pull request has been merged in 5e64e90. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Removes the
ensureInstance(ref.current, ReactNativeElement)pattern from Fantom tests. Host refs are typed asHostInstanceand read withnullthrows(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 theReactNativeElement/ensureInstanceimports 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 standardinstanceof HTMLElement(a global), since React Native elements are instances ofHTMLElementat runtime.This also covers the internal
-itest.fb.jstests and the shared ShadowNode test utilities (ShadowNodeReferenceCounter/ShadowNodeRevisionGetter), which now type their refs asHostInstance.Known follow-up: the RN Flow global type definitions still need to be fixed. At the type level
HTMLElementdoes not matchHostInstanceyet, even though the runtime values do. Because of this,HTMLElementcannot be used where a narrowed value flows into RN-internal APIs typed asHostInstance/ReadOnlyNode(e.g.VirtualView, which instead types its helper params asHostInstancedirectly and passes them through without a narrowing check). Aligning theHTMLElementglobal definition withHostInstancewould let those remaining spots useHTMLElementtoo.This is a test-only change with no runtime or user-facing impact.
Changelog:
[Internal]
Differential Revision: D110888634