diff --git a/packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js b/packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js index 817c01f187202..88d30a81f0a79 100644 --- a/packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js +++ b/packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js @@ -464,10 +464,6 @@ function fastAddProperties( for (const propKey in props) { const prop = props[propKey]; - if (prop === undefined) { - continue; - } - const attributeConfig = ((validAttributes[ propKey ]: any): AttributeConfiguration); @@ -478,7 +474,14 @@ function fastAddProperties( let newValue; - if (typeof prop === 'function') { + if (prop === undefined) { + // Discard the prop if it was previously defined. + if (payload && payload[propKey] !== undefined) { + newValue = null; + } else { + continue; + } + } else if (typeof prop === 'function') { // A function prop. It represents an event handler. Pass it to native as 'true'. newValue = true; } else if (typeof attributeConfig !== 'object') { diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeAttributePayloadFabric-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeAttributePayloadFabric-test.internal.js index 68cf318c6f126..9136c932e601e 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeAttributePayloadFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeAttributePayloadFabric-test.internal.js @@ -60,7 +60,16 @@ describe('ReactNativeAttributePayloadFabric.create', () => { }); }); - it('should ignore fields that are set to undefined', () => { + it('should nullify previously defined style prop that is subsequently set to null or undefined', () => { + expect( + create({style: [{a: 0}, {a: undefined}]}, {style: {a: true}}), + ).toEqual({a: null}); + expect(create({style: [{a: 0}, {a: null}]}, {style: {a: true}})).toEqual({ + a: null, + }); + }); + + it('should ignore non-style fields that are set to undefined', () => { expect(create({}, {a: true})).toEqual(null); expect(create({a: undefined}, {a: true})).toEqual(null); expect(create({a: undefined, b: undefined}, {a: true, b: true})).toEqual(