From 83123db52be7fda857b2e230856ad23be1d49b2c Mon Sep 17 00:00:00 2001 From: ben cripps Date: Tue, 1 Sep 2026 14:27:54 -0500 Subject: [PATCH] fix: Ignore undefined style values on native Co-authored-by: Cursor --- .../src/native/css/processStyle.js | 7 +++++++ .../tests/css/css-create-test.native.js | 16 ++++++++++++++++ 2 files changed, 23 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..ebf1e629 100644 --- a/packages/react-strict-dom/src/native/css/processStyle.js +++ b/packages/react-strict-dom/src/native/css/processStyle.js @@ -73,6 +73,13 @@ export function processStyle( for (const propName in style) { const styleValue = style[propName]; + // Drop undefined values so they don't reach the style resolver, which + // only accepts strings, numbers, objects, or null. This matches web + // behavior and lets style functions return undefined to omit 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); + }); }); /**