Skip to content

Add getTextLayout() to Text refs (#60414) - #60414

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
markv:export-D134142257
Dec 2, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
markv:export-D134142257

Conversation

@markv

@markv markv commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

onTextLayout reaches JS after the first frame with the text is drawn, so output that depends on a text's lines shows unadjusted for a few frames.

This adds getTextLayout() to refs of a <Text> not nested in another <Text>. It synchronously returns {lines}, the same shape and lines as the onTextLayout event, so a layout effect can use them in the same commit.

  • ParagraphShadowNode keeps the lines it measures for onTextLayout and exposes them through TextLayoutLinesProvider, a header-only interface.
  • dom::getTextLayoutLines reads them through that interface; NativeDOM.getTextLayout resolves the revision and builds the {lines} object.
  • Text adds the method before the ref receives the instance, only when a ref is passed; nested texts don't get it.

Changelog:
[General][Added] - Add getTextLayout() to <Text> refs

Reviewed By: rubennorte

Differential Revision: D134142257

@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 Nov 30, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

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

@rubennorte rubennorte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@github-actions

Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

Summary:

`onTextLayout` reaches JS after the first frame with the text is drawn, so output that depends on a text's lines shows unadjusted for a few frames.

This adds `getTextLayout()` to refs of a `<Text>` not nested in another `<Text>`. It synchronously returns `{lines}`, the same shape and lines as the `onTextLayout` event, so a layout effect can use them in the same commit.
- `ParagraphShadowNode` keeps the lines it measures for `onTextLayout` and exposes them through `TextLayoutLinesProvider`, a header-only interface.
- `dom::getTextLayoutLines` reads them through that interface; `NativeDOM.getTextLayout` resolves the revision and builds the `{lines}` object.
- `Text` adds the method before the ref receives the instance, only when a ref is passed; nested texts don't get it.

Changelog:
[General][Added] - Add `getTextLayout()` to `<Text>` refs

Reviewed By: rubennorte

Differential Revision: D134142257
@meta-codesync meta-codesync Bot changed the title Add getTextLayout() to Text refs Add getTextLayout() to Text refs (#60414) Dec 1, 2026
@markv
markv force-pushed the export-D134142257 branch from 5e61d9a to b62957a Compare December 1, 2026 23:59
@meta-codesync
meta-codesync Bot merged commit 2d0b824 into react:main Dec 2, 2026
102 of 105 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @markv in 2d0b824

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 2, 2026
ide added a commit to expo/react-native that referenced this pull request Dec 4, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
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.

3 participants