From 6deaee7b50366f7dfb88752b5307edbb88e00cfd Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:21:54 +0100 Subject: [PATCH] Send null when removing TextInput fontSize with props diffing Summary: `fontSize` was sent from a flat field that defaults to 0, so removing it called `setFontSize(0)` and made the placeholder and any new text invisible. This sends `fontSize` from `textAttributes.fontSize`, which is NaN when unset, and sends `null` when it is removed. `ReactTextInputManager` then applies its default font size, the same as with raw props. It also means an explicit `fontSize: 0` is now sent like any other value. TextInput doesn't use props diffing yet: `getDiffPropsImplementationTarget()` returns `TextInput`, which doesn't match the `AndroidTextInput` component name. So the problem above only appears once that is enabled, and this change has no runtime effect until then. Changelog: [Internal] - Send null when removing TextInput fontSize with props diffing Test Plan: `AndroidTextInputPropsDiffTest.removedFontSizeIsSentAsNull` compares the props diffing payload with the raw props payload. It fails without this change and passes with it. Co-Authored-By: Claude Opus 5.5 --- .../androidtextinput/AndroidTextInputProps.cpp | 8 ++++++-- .../tests/AndroidTextInputPropsDiffTest.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp index ad0296c3f010..1498b534ba1c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace facebook::react { @@ -625,8 +626,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps( result["letterSpacing"] = letterSpacing; } - if (fontSize != oldProps->fontSize) { - result["fontSize"] = fontSize; + if (!floatEquality( + textAttributes.fontSize, oldProps->textAttributes.fontSize)) { + result["fontSize"] = std::isnan(textAttributes.fontSize) + ? folly::dynamic(nullptr) + : textAttributes.fontSize; } if (textAlign != oldProps->textAlign) { diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp index d549c31fd8d9..7928294876b1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp @@ -55,6 +55,18 @@ TEST(AndroidTextInputPropsDiffTest, removedColorsAreSentAsNull) { } } +// 0 is the default of the flat field, and a font size of 0 hides the +// placeholder and new text. +TEST(AndroidTextInputPropsDiffTest, removedFontSizeIsSentAsNull) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object("fontSize", 20)}, + {dynamic::object("fontSize", 0)}, + {dynamic::object("fontSize", 20)}, + {dynamic::object("fontSize", nullptr)}, + }); +} + } // namespace facebook::react #endif