Use public unstable_TextAncestorContext API#477
Open
yaminyassin wants to merge 4 commits into
Open
Conversation
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.
This was referenced May 13, 2026
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. |
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.
React Native 0.81 promoted
TextAncestorContextto a public API in facebook/react-native#52368, so we no longer need to reach intoreact-native/Libraries/Text/TextAncestor.The deep-import file on the RN side only exists as a shim for this repo:
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: importunstable_TextAncestorContextfromreact-nativeinstead of the deep path.tests/__mocks__/react-native/index.js: exportunstable_TextAncestorContextso the mock matches.tests/__mocks__/react-native/Libraries/Text/TextAncestor.js: deleted, no longer referenced.Depends on
#475 —
unstable_TextAncestorContextneeds React Native ≥ 0.81, which the peer-dep bump there handles.