Skip to content

Commit b0d469e

Browse files
committed
Fix fastAddPropertiess to properly nullify style props.
1 parent 8b08e99 commit b0d469e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ function fastAddProperties(
464464
for (const propKey in props) {
465465
const prop = props[propKey];
466466

467-
if (prop === undefined) {
468-
continue;
469-
}
470-
471467
const attributeConfig = ((validAttributes[
472468
propKey
473469
]: any): AttributeConfiguration);
@@ -478,7 +474,14 @@ function fastAddProperties(
478474

479475
let newValue;
480476

481-
if (typeof prop === 'function') {
477+
if (prop === undefined) {
478+
// Discard the prop if it was previously defined.
479+
if (payload && payload[propKey] !== undefined) {
480+
newValue = null;
481+
} else {
482+
continue;
483+
}
484+
} else if (typeof prop === 'function') {
482485
// A function prop. It represents an event handler. Pass it to native as 'true'.
483486
newValue = true;
484487
} else if (typeof attributeConfig !== 'object') {

packages/react-native-renderer/src/__tests__/ReactNativeAttributePayloadFabric-test.internal.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ describe('ReactNativeAttributePayloadFabric.create', () => {
6060
});
6161
});
6262

63-
it('should ignore fields that are set to undefined', () => {
63+
it('should nullify previously defined style prop that is subsequently set to null or undefined', () => {
64+
expect(
65+
create({style: [{a: 0}, {a: undefined}]}, {style: {a: true}}),
66+
).toEqual({a: null});
67+
expect(create({style: [{a: 0}, {a: null}]}, {style: {a: true}})).toEqual({
68+
a: null,
69+
});
70+
});
71+
72+
it('should ignore non-style fields that are set to undefined', () => {
6473
expect(create({}, {a: true})).toEqual(null);
6574
expect(create({a: undefined}, {a: true})).toEqual(null);
6675
expect(create({a: undefined, b: undefined}, {a: true, b: true})).toEqual(

0 commit comments

Comments
 (0)