Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Comment on lines +63 to +70
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fastAddProperties tested in this codepath? Can we run these tests with enableAddPropertiesFastPath enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with

yarn test packages/react-native-renderer -r=xplat --variant=true


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(
Expand Down