From e3372ac18f77e5431552df09055394776bb332ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 15 Oct 2024 18:12:54 +0200 Subject: [PATCH] fix: handle properly null and undefined props values Co-authored-by: Julien --- src/inertia.ts | 6 +++++- tests/inertia.spec.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/inertia.ts b/src/inertia.ts index 9dfb370..dd61ff8 100644 --- a/src/inertia.ts +++ b/src/inertia.ts @@ -103,7 +103,11 @@ export class Inertia { */ if (!isPartial) { newProps = Object.fromEntries( - Object.entries(props).filter(([_, value]) => !(value as any)[ignoreFirstLoadSymbol]) + Object.entries(props).filter(([_, value]) => { + if (value && (value as any)[ignoreFirstLoadSymbol]) return false + + return true + }) ) } diff --git a/tests/inertia.spec.ts b/tests/inertia.spec.ts index 3c4d648..656a839 100644 --- a/tests/inertia.spec.ts +++ b/tests/inertia.spec.ts @@ -212,6 +212,24 @@ test.group('Inertia', () => { assert.deepEqual(result.mergeProps, ['baz', 'bar']) }) + test('properly handle null and undefined values props on first visit', async ({ assert }) => { + setupViewMacroMock() + + const inertia = await new InertiaFactory().create() + + const result: any = await inertia.render('Auth/Login', { + user: undefined, + password: null, + message: 'hello', + }) + + assert.deepEqual(result.props.page.props, { + message: 'hello', + password: null, + user: undefined, + }) + }) + test("don't return lazy props on first visit", async ({ assert }) => { setupViewMacroMock()