Reset removed shadow, editable and persistentScrollbar props to their defaults (#59125)

Summary:
A prop removed from a component reaches the C++ props as `null`, and `convertRawProp` then returns its fallback argument. For these props the fallback differs from the field's declared default, so a component that had the prop and lost it is left with a value that a component which never had it does not have:

| Prop | Declared default | After removal |
| --- | --- | --- |
| `shadowRadius` | `3` | `0` |
| `shadowOffset` | `{width: 0, height: -3}` | `{width: 0, height: 0}` |
| `editable` (TextInput) | `true` | `false` |
| `persistentScrollbar` (ScrollView) | `false` | `true` |
| `sendMomentumEvents`, `nestedScrollEnabled` (Android ScrollView) | `false` | `true` |

On iOS, `RCTViewComponentView` applies the shadow values to the layer, so a view that sets `shadowRadius` or `shadowOffset` conditionally (a raised card, a pressed state) gets `layer.shadowRadius = 0` and `layer.shadowOffset = {0, 0}` once they are removed, instead of the defaults it started with. On Android, the props diff of `enablePropsUpdateReconciliationAndroid` reads the same values, so a `TextInput` that drops `editable={false}` stays read-only and a `ScrollView` that drops `persistentScrollbar` keeps it. `ScrollView` always passes `sendMomentumEvents` and `nestedScrollEnabled`, so those two only reach a direct user of the native component.

Each fallback is now the declared default, the value `setProp` (`enableCppPropsIteratorSetter`) already resets these props to.

## Changelog:

[GENERAL] [FIXED] - Reset a removed `shadowRadius`, `shadowOffset`, `editable` or `persistentScrollbar` prop to its default

Pull Request resolved: https://github.com/react/react-native/pull/59125

Test Plan:
- `ViewPropsTest` and `BaseTextInputPropsTest` parse a prop, then its removal, and compare the result with a default-constructed props object. On `main` they fail with `removed.shadowRadius` 0 against 3, `removed.shadowOffset.height` 0 against -3, and `removed.editable` false against true. `BaseTextInputProps` had no tests, so `textinput/tests/` is new: the SwiftPM target excludes it as the other targets exclude theirs, and the internal BUCK file now defines and links a `:tests` target. The view test target also declares the direct dependencies used by the new regression tests.
- A Fantom case in `ScrollView-itest.js` renders `persistentScrollbar={true}` and then no prop; on `main` the second render still carries `persistentScrollbar="true"`.
- I ran these in the `reactnativecommunity/react-native-android` image, linking the gtests against the Fantom runner's ReactCommon build: the new tests fail on `main` and pass with this change, and the whole Fantom suite passes with it. clang-format 21.1.2, Prettier, ESLint and Flow pass.
- RNTester release builds of `main` and of this change on an iPad (iOS 27.0.1): a view that loses `shadowRadius` and `shadowOffset` draws no shadow on `main` and the default one with this change ([before and after](https://github.com/react/react-native/pull/59125#issuecomment-6211033307)).
- Internal validation after the BUCK updates: `buck2 test -j 16 fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/components/textinput:tests fbsource//xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/components/view:tests -- --timeout=300` passed all 96 tests, including the new editable and shadow prop-removal regressions ([test run](https://www.internalfb.com/intern/testinfra/testrun/30680772508413679)). `arc f` and `arc lint -a` passed.
- Apple follow-up validation: reproduced both `testsApple` analysis failures with `buck2 build --flagfile fbsource//fbobjc/mode/buck2/ios-tests -c cxx.default_platform=iphonesimulator-arm64` before this update ([failure](https://www.internalfb.com/intern/sandcastle/instance/22518001181223006/)). The direct `core` dependencies caused Buck to import private core headers because the test target basename matches the core test registration. Removing those redundant dependencies avoids the basename `conversions.h` collisions while preserving access to the exported core headers through the component dependencies. Both Apple targets now build successfully ([build](https://www.internalfb.com/buck2/0e4dea76-a9d8-4bec-8fc9-9f74701bfd96)). Running the same two targets with `buck2 test` in the iOS-tests mode passes all 100 tests ([Apple test run](https://www.internalfb.com/intern/testinfra/testrun/11821949232723115)); the Linux targets on the updated base pass all 98 tests ([Linux test run](https://www.internalfb.com/intern/testinfra/testrun/3659175102648737)). `arc f` and focused `arc lint -a` on both BUCK files pass.
- Current cross-platform BUCK validation: the Android linker failure in `textinput:testsAndroid` reproduces locally using the exact CI command, `buck2 build --flagfile fbsource//fbandroid/mode/integration-tests-allowed-abi-x86` ([before](https://www.internalfb.com/buck2/f06f5508-6e4c-477e-ab58-9ec31f031e47)). A `test-deps` library now exports the core, view and attributed-string dependencies, matching the existing core test-dependency pattern. This links the symbols used by inline/default props constructors on Android without giving the Apple test direct access to conflicting private headers. The exact Android build now passes ([after](https://www.internalfb.com/buck2/856b54eb-3183-40e9-8237-60eae8a49158)). Both textinput and view test packages build for x86/x86_64 and armeabi-v7a/arm64-v8a, including the 32-bit target variants ([ARM build](https://www.internalfb.com/buck2/95780495-d6f6-47e8-98bc-f90275fc524a)). On the same Linux checkout, the iOS-tests-mode Buck run passes 100/100 tests ([Apple](https://www.internalfb.com/intern/testinfra/testrun/1688850268234094)) and the Linux run passes 98/98 tests ([Linux](https://www.internalfb.com/intern/testinfra/testrun/27303072800788143)). Android `buck2 test` successfully built the packages but reported `NO TESTS RAN`, so no Android runtime test pass is claimed. `arc f` and focused `arc lint -a` pass.

Reviewed By: christophpurrer

Differential Revision: D125706127

Pulled By: javache

fbshipit-source-id: c94b7a1d2e96cc59a958b34bc3242e2fc71d1fcd
This commit is contained in:
Yevhenii authored and meta-codesync[bot] committed 2026-10-21 09:31:54 -07:00
1 parent 1423ef001d
commit 86695d8eb6
8 files changed
+136 -7

No files matched your search

@@ -41,6 +41,34 @@ describe('<ScrollView>', () => {
</rn-scrollView>,
);
});
it('returns persistentScrollbar to its default once the prop is removed', () => {
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(<ScrollView persistentScrollbar={true} />);
});
expect(
root.getRenderedOutput({props: ['persistentScrollbar']}).toJSX(),
).toEqual(
<rn-scrollView persistentScrollbar="true">
<rn-view />
</rn-scrollView>,
);
Fantom.runTask(() => {
root.render(<ScrollView />);
});
expect(
root.getRenderedOutput({props: ['persistentScrollbar']}).toJSX(),
).toEqual(
<rn-scrollView>
<rn-view />
</rn-scrollView>,
);
});
});
describe('ref', () => {
+1 -1
View File
@@ -563,7 +563,7 @@ let reactFabricText = RNTarget(
let reactFabricTextInput = RNTarget(
name: .reactFabricTextInput,
path: "ReactCommon/react/renderer/components/textinput",
excludedPaths: ["platform/android", "platform/macos"],
excludedPaths: ["tests", "platform/android", "platform/macos"],
dependencies: [.reactNativeDependencies, .reactCore, .reactJsiExecutor, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .yoga, .reactRendererDebug, .reactGraphics, .reactFabric, .reactTurboModuleBridging, .reactFabricTextLayoutManager, .reactImageManagerApple],
sources: [".", "platform/ios"]
)
@@ -164,7 +164,7 @@ BaseScrollViewProps::BaseScrollViewProps(
rawProps,
"persistentScrollbar",
sourceProps.persistentScrollbar,
true)),
false)),
horizontal(convertRawProp(
context,
rawProps,
@@ -25,13 +25,13 @@ HostPlatformScrollViewProps::HostPlatformScrollViewProps(
rawProps,
"sendMomentumEvents",
sourceProps.sendMomentumEvents,
true)),
false)),
nestedScrollEnabled(convertRawProp(
context,
rawProps,
"nestedScrollEnabled",
sourceProps.nestedScrollEnabled,
true)),
false)),
fadingEdgeLength(convertRawProp(
context,
rawProps,
@@ -104,7 +104,7 @@ BaseTextInputProps::BaseTextInputProps(
rawProps,
"editable",
sourceProps.editable,
{})),
true)),
readOnly(convertRawProp(
context,
rawProps,
@@ -0,0 +1,43 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/renderer/components/textinput/BaseTextInputProps.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsParser.h>
namespace facebook::react {
namespace {
BaseTextInputProps parse(
const folly::dynamic& rawPropsValue,
const BaseTextInputProps& sourceProps = BaseTextInputProps()) {
ContextContainer contextContainer{};
PropsParserContext parserContext{-1, contextContainer};
auto raw = RawProps(rawPropsValue);
auto parser = RawPropsParser();
parser.prepare<BaseTextInputProps>();
raw.parse(parser);
return {parserContext, sourceProps, raw};
}
} // namespace
TEST(BaseTextInputPropsTest, removed_editable_returns_to_its_default) {
auto readOnly = parse(folly::dynamic::object("editable", false));
ASSERT_FALSE(readOnly.editable);
auto removed = parse(folly::dynamic::object("editable", nullptr), readOnly);
EXPECT_EQ(removed.editable, BaseTextInputProps().editable);
}
} // namespace facebook::react
@@ -180,7 +180,7 @@ BaseViewProps::BaseViewProps(
rawProps,
"shadowOffset",
sourceProps.shadowOffset,
{})),
Size{0, -3})),
shadowOpacity(convertRawProp(
context,
rawProps,
@@ -192,7 +192,7 @@ BaseViewProps::BaseViewProps(
rawProps,
"shadowRadius",
sourceProps.shadowRadius,
{})),
(Float)3)),
cursor(
convertRawProp(context, rawProps, "cursor", sourceProps.cursor, {})),
boxShadow(convertRawProp(
@@ -0,0 +1,58 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsParser.h>
namespace facebook::react {
namespace {
ViewProps parse(
const folly::dynamic& rawPropsValue,
const ViewProps& sourceProps = ViewProps()) {
ContextContainer contextContainer{};
PropsParserContext parserContext{-1, contextContainer};
auto raw = RawProps(rawPropsValue);
auto parser = RawPropsParser();
parser.prepare<ViewProps>();
raw.parse(parser);
return {parserContext, sourceProps, raw};
}
} // namespace
TEST(ViewPropsTest, removed_shadow_radius_returns_to_its_default) {
auto withShadowRadius = parse(folly::dynamic::object("shadowRadius", 8));
ASSERT_EQ(withShadowRadius.shadowRadius, 8);
auto removed =
parse(folly::dynamic::object("shadowRadius", nullptr), withShadowRadius);
EXPECT_EQ(removed.shadowRadius, ViewProps().shadowRadius);
}
TEST(ViewPropsTest, removed_shadow_offset_returns_to_its_default) {
auto withShadowOffset = parse(
folly::dynamic::object(
"shadowOffset", folly::dynamic::object("width", 2)("height", 4)));
ASSERT_EQ(withShadowOffset.shadowOffset, (Size{.width = 2, .height = 4}));
auto removed =
parse(folly::dynamic::object("shadowOffset", nullptr), withShadowOffset);
const auto defaultShadowOffset = ViewProps().shadowOffset;
EXPECT_EQ(removed.shadowOffset.width, defaultShadowOffset.width);
EXPECT_EQ(removed.shadowOffset.height, defaultShadowOffset.height);
}
} // namespace facebook::react