Skip to content

Use public unstable_TextAncestorContext API#477

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

Use public unstable_TextAncestorContext API#477
yaminyassin wants to merge 1 commit 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.

@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.

@martinbooth
Copy link
Copy Markdown
Contributor

martinbooth commented May 15, 2026

Thank you! I think the branch associated with this pull request has several other commits/features though. If you're able to separate the Use public unstable_TextAncestorContext API commit from the other changes I will merge

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 yaminyassin force-pushed the chore/use-public-text-ancestor-context branch from 1f844c0 to 39f7828 Compare May 15, 2026 09:59
@yaminyassin
Copy link
Copy Markdown
Author

Done! only the Use public unstable_TextAncestorContext API commit remains.

Quick heads-up before you merge: unstable_TextAncestorContext needs RN ≥ 0.81, but main's peer dep is still >=0.79.5. So on its own this could break for users on 0.79.x or 0.80.x.

Easiest fix is probably merging #475 first since it bumps the peer dep anyway. But if you'd rather take this one first, I can tack on a >=0.81.0 bump here. Let me know what you prefer.

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.

2 participants