fix: app‑extension‑safe guard and fallback in RCTFontSizeMultiplier() #54952
+8
−1
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.
Summary:
This change fixes a text rendering issue on iOS when using the new architecture (Fabric), most notably in app extensions on iOS.
While migrating an app extension to the new architecture, all the labels in our app became invisible. A bare
<Text>component initially appeared to work, which made the issue hard to track down.Text rendered correctly with default styles, but once
fontSizeorfontFamilywas applied, text would ignore sizing or become invisible. Because text was still visible by default, the problem did not immediately appear to be related to font scaling or measurement, so it took me WEEKS to understand.Please check out the issue I created almost a month ago: #54642
After deeper investigation into Fabric text measurement and after using 100 different breakpoint attempts, the root cause turned out to be an invalid font size multiplier coming from
RCTFontSizeMultiplier()when running inside an app extension.In app extensions,
RCTSharedApplication()can (or will!) returnnil. When that happened,RCTFontSizeMultiplier()could return an invalid value, which later caused Fabric text measurement to produce zero-height paragraphs. As a result,<Text>components could ignorefontSizeor become invisible whenfontFamilywas set.The fix makes
RCTFontSizeMultiplier()app-extension-safe by returning a positive default (1.0) whenUIApplicationor the preferred content size category is unavailable, and by clamping invalid values.Related issue:
#54642
Changelog:
[IOS] [FIXED] - Make
RCTFontSizeMultiplier()app-extension-safe by adding a default fallback and clamping invalid values to a positive number, such that fonts are never scaled down to zeroTest Plan:
<Text>rendering correctly by default but ignoringfontSizeor becoming invisible whenfontFamilywas appliedRCTFontSizeMultiplier()fontSizeTo test this fix the repro that I provided in the issue above can easily be used.
First run the code without the commit (observe the bad outcome) then run it with the commit (observe the good outcome)