From a280ec439b353514e4ada100ee50548d856ecedc Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Sun, 24 May 2026 05:34:14 -0700 Subject: [PATCH] Ignore undefined style values on native --- .../src/native/css/processStyle.js | 8 ++++++++ .../tests/css/css-create-test.native.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/react-strict-dom/src/native/css/processStyle.js b/packages/react-strict-dom/src/native/css/processStyle.js index 7329436f..754d338b 100644 --- a/packages/react-strict-dom/src/native/css/processStyle.js +++ b/packages/react-strict-dom/src/native/css/processStyle.js @@ -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}"`); diff --git a/packages/react-strict-dom/tests/css/css-create-test.native.js b/packages/react-strict-dom/tests/css/css-create-test.native.js index 2067238f..73910dfa 100644 --- a/packages/react-strict-dom/tests/css/css-create-test.native.js +++ b/packages/react-strict-dom/tests/css/css-create-test.native.js @@ -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(); + }); + 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); + }); }); /**