Skip to content

Use public unstable_TextAncestorContext API#477

Open
yaminyassin wants to merge 4 commits into
facebook:mainfrom
yaminyassin:chore/use-public-text-ancestor-context
Open

Use public unstable_TextAncestorContext API#477
yaminyassin wants to merge 4 commits into
facebook:mainfrom
yaminyassin:chore/use-public-text-ancestor-context

Conversation

@yaminyassin
Copy link
Copy Markdown

@yaminyassin yaminyassin commented May 13, 2026

React Native 0.81 promoted TextAncestorContext to a public API in facebook/react-native#52368, so we no longer need to reach into
react-native/Libraries/Text/TextAncestor.

The deep-import file on the RN side only exists as a shim for this repo:

// Compatibility module for ReactStrictDOMTextAncestorContext.native.js.flow (react-strict-dom)
// TODO(huntie): Delete after we've fixed this cross-repo reference

import TextAncestorContext from './TextAncestorContext';
export default TextAncestorContext;

So merging this clears the cross-repo reference the TODO is waiting on, and the shim can be deleted on the RN side afterwards (I'll open that PR once this lands).

It's the same Context object under the hood — no behavior change, snapshots are unchanged.

Changes

  • src/native/react-native/TextAncestorContext.js: import unstable_TextAncestorContext from react-native instead of the deep path.
  • tests/__mocks__/react-native/index.js: export unstable_TextAncestorContext so the mock matches.
  • tests/__mocks__/react-native/Libraries/Text/TextAncestor.js: deleted, no longer referenced.

Depends on

#475unstable_TextAncestorContext needs React Native ≥ 0.81, which the peer-dep bump there handles.

Yamin Yassin added 4 commits May 12, 2026 23:20
Bump the react-native peer dependency to >=0.82.0 and rewrite
useStrictDOMElement to wrap the underlying RN host node in a thin
Proxy instead of cloning it via Object.create / Object.defineProperties.

React Native 0.82 shipped the stable DOM Node APIs that strict-dom
helped drive into RN (DOM traversal, ownerDocument, getRootNode,
children/childNodes, pointer-capture methods, etc.), so the native
ref polyfill becomes a lightweight overlay rather than a parallel
implementation. The Proxy traps only the keys strict-dom still needs
to control:

- nodeName: uppercase DOM name (RN exposes tagName as 'RN:View')
- getBoundingClientRect and length getters: divided by the active
  viewportScale
- <img>.complete: fallback to false when the underlying RN Image
  node does not expose it
- <input>/<textarea> selection trio (setSelectionRange,
  selectionStart, selectionEnd): polyfilled on top of setSelection
  while RN's TextInput lacks the W3C selection API

Everything else (ownerDocument, getRootNode, parentNode, children,
childNodes, sibling navigation, pointer-capture, legacy measure*)
forwards directly to the underlying RN node via Reflect.get. Function
values are bound to the target so internal `this`-references inside
RN's implementations resolve correctly.

Identity caching via a WeakMap<Node, Proxy> is preserved so the same
underlying RN node always yields the same wrapped ref.

The selection polyfill is gated on the underlying property being
absent, so the day RN exposes the W3C selection API on TextInput the
polyfill self-disables.

RN 0.83 also tightened the Flow types around Animated.createAnimatedComponent
(now a single-type-arg generic) and made ImageProps / TextInputProps
exact. The Animated factory call sites are updated to the new
signature; the wide-spread of strict-dom's ReactNativeProps onto the
exact host components is suppressed with targeted $FlowFixMe
annotations (real follow-up tracked separately).

Adds 10 ref tests in tests/html/html-refs-test.native.js documenting
the contract: uppercase nodeName, getBoundingClientRect pass-through
at scale=1, getBoundingClientRect scaled when viewportScale != 1, the
DOM Node API pass-through (ownerDocument / getRootNode / childNodes /
children), identity stability of the strict ref across renders, and
the <img>.complete fallback (both when omitted and when provided).

Bundle size: native/index.js drops ~363 minified / ~69 brotli bytes.
Web build is byte-identical.
Bring apps/expo-app and apps/platform-tests onto a real RN >=0.82.0
runtime so they exercise the new useStrictDOMElement Proxy path
against the DOM Node APIs from the previous commit.

Note: there is no Expo SDK that pairs exactly with RN 0.82 (SDK 53 =
RN 0.79, SDK 54 ~= RN 0.81, SDK 55 = RN 0.83). SDK 55 / RN 0.83.6
still satisfies the library's >=0.82.0 peer dep and ships the same
DOM Node API surface, so it is the closest landing zone.

Co-traveling dependency versions (@expo/metro-runtime,
expo-build-properties, expo-status-bar, react-native-web, etc.) come
from `npx expo install --check` for SDK 55; no hand-rolled versions.

Also pin react / react-dom / react-test-renderer to ~19.2.0 across
the workspace root and the two library packages' devDependencies.
RN 0.82+ requires React >=19.1.1, and aligning the workspace devDeps
avoids a multiple-React-instances error in the jest suite that would
otherwise surface once the apps hoist React 19.2.x at the root.
React Native 0.81 exposed TextAncestorContext as a public API
(facebook/react-native#52368). Switch from the deep import path
'react-native/Libraries/Text/TextAncestor' to the public
'unstable_TextAncestorContext' export.

The deep-import target file in React Native exists solely as a
backwards-compatibility shim for react-strict-dom — see
https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Text/TextAncestor.js
which carries a TODO from @huntie to delete it once this cross-repo
reference is fixed.

Same React Context object, no behavioral change. Test mock updated
to match the new import path; old deep-import mock deleted.
@yaminyassin
Copy link
Copy Markdown
Author

Cross-repo follow-up: facebook/react-native#56813 (draft) deletes the now-unneeded compatibility shim on the React Native side. It's gated on this PR landing and a strict-dom release shipping with the new import path.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant