Skip to content

Add iOS tests for RCTTextLayoutManager, two of which assert the notifications it posts today - #60169

Open
ejc3 wants to merge 1 commit into
react:mainfrom
ejc3:export-D133310818
Open

ejc3 wants to merge 1 commit into
react:mainfrom
ejc3:export-D133310818

Conversation

@ejc3

@ejc3 ejc3 commented Nov 19, 2026

Copy link
Copy Markdown

Summary:
This adds RCTTextLayoutManagerTests, four iOS tests for RCTTextLayoutManager. It changes no production code.

Two of the tests assert a defect that exists today, so they pass on the current code. The change that follows this one fixes the defect, renames these two tests, and inverts their assertions. The other two tests compare what RCTTextLayoutManager lays out and draws with a TextKit stack that the test builds on a plain NSTextStorage. The fix has to keep those two comparisons passing.

The defect

RCTTextLayoutManager creates an NSTextStorage for each layout call, on the JavaScript thread. NSTextStorage posts two notifications to the default notification center for every edit, including the one that gives it its text. If an observer was added for them with addObserverForName:object:queue:usingBlock: and the main queue, the thread that posts waits until the main thread has run the observer's block. UIKit adds such an observer for a search field, and that observer receives the notifications of every text storage in the process.

The main thread blocks on the JavaScript thread when it flushes an event synchronously, for example an experimental_onSafeAreaInsetsChange event that a view emits from layoutSubviews. When a measurement and a synchronous flush overlap in an app that has such an observer, each thread waits for the other, and the app stops drawing and no longer answers touches. This was seen in a debug build.

The tests

  • testMeasuringPostsTextStorageNotifications and testMeasuringOffTheMainThreadWaitsForAMainQueueObserver measure a plain text, a text with a line height, and a text that is shrunk to fit one line. The first asserts that the measurements post text storage notifications. The second adds a main-queue observer and measures on a background queue while the main thread is blocked for one second. It asserts that the measurements finish only after the main queue has run the observer.
  • testLinesMatchAPlainTextStorage and testDrawingMatchesAPlainTextStorage use ten texts (one word, a sentence that wraps, mixed font sizes, emoji, CJK, Arabic, Thai and Devanagari, explicit newlines, a line height, and a named font family) and three paragraph settings (no line limit, two lines with a truncated tail, and one line with adjustsFontSizeToFit). The first compares the text, rectangle, and baseline of every line at three widths. The second compares the drawn pixels.

Changelog: [Internal]

Differential Revision: D133310818

…ications it posts today

Summary:
This adds `RCTTextLayoutManagerTests`, four iOS tests for `RCTTextLayoutManager`. It changes no production code.

Two of the tests assert a defect that exists today, so they pass on the current code. The change that follows this one fixes the defect, renames these two tests, and inverts their assertions. The other two tests compare what `RCTTextLayoutManager` lays out and draws with a TextKit stack that the test builds on a plain `NSTextStorage`. The fix has to keep those two comparisons passing.

**The defect**

`RCTTextLayoutManager` creates an `NSTextStorage` for each layout call, on the JavaScript thread. `NSTextStorage` posts two notifications to the default notification center for every edit, including the one that gives it its text. If an observer was added for them with `addObserverForName:object:queue:usingBlock:` and the main queue, the thread that posts waits until the main thread has run the observer's block. UIKit adds such an observer for a search field, and that observer receives the notifications of every text storage in the process.

The main thread blocks on the JavaScript thread when it flushes an event synchronously, for example an `experimental_onSafeAreaInsetsChange` event that a view emits from `layoutSubviews`. When a measurement and a synchronous flush overlap in an app that has such an observer, each thread waits for the other, and the app stops drawing and no longer answers touches. This was seen in a debug build.

**The tests**

- `testMeasuringPostsTextStorageNotifications` and `testMeasuringOffTheMainThreadWaitsForAMainQueueObserver` measure a plain text, a text with a line height, and a text that is shrunk to fit one line. The first asserts that the measurements post text storage notifications. The second adds a main-queue observer and measures on a background queue while the main thread is blocked for one second. It asserts that the measurements finish only after the main queue has run the observer.
- `testLinesMatchAPlainTextStorage` and `testDrawingMatchesAPlainTextStorage` use ten texts (one word, a sentence that wraps, mixed font sizes, emoji, CJK, Arabic, Thai and Devanagari, explicit newlines, a line height, and a named font family) and three paragraph settings (no line limit, two lines with a truncated tail, and one line with `adjustsFontSizeToFit`). The first compares the text, rectangle, and baseline of every line at three widths. The second compares the drawn pixels.

Changelog: [Internal]

Differential Revision: D133310818
@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 19, 2026
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 7cf5b351b48a.

android: no capture

This branch has not been deployed

No deployments
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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant