Skip to content
Open
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
8 changes: 8 additions & 0 deletions packages/react-strict-dom/src/native/css/processStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export function processStyle(
for (const propName in style) {
const styleValue = style[propName];

// Drop "undefined" values so they don't reach the underlying style
// resolver, which only accepts strings, numbers, objects or null. This
// mirrors web behavior, where undefined values are ignored, and lets
// inline style functions return undefined to opt out of a property.
if (styleValue === undefined) {
continue;
}

if (skipValidation !== true && !isAllowedStyleKey(propName)) {
if (__DEV__) {
warnMsg(`unsupported style property "${propName}"`);
Expand Down
16 changes: 16 additions & 0 deletions packages/react-strict-dom/tests/css/css-create-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,22 @@ describe('css.create()', () => {
});
expect(root.toJSON().props.style).toMatchSnapshot();
});

test('undefined values are ignored', () => {
const styles = css.create({
root: (gap) => ({
rowGap: gap
})
});
let root;
act(() => {
root = create(<html.div style={styles.root(undefined)} />);
});
const { style } = root.toJSON().props;
// The property is dropped rather than passed through as undefined,
// which would otherwise be rejected by the style resolver.
expect(Object.prototype.hasOwnProperty.call(style, 'rowGap')).toBe(false);
});
});

/**
Expand Down