Skip to content

Commit

Permalink
fix: handle properly null and undefined props values
Browse files Browse the repository at this point in the history
Co-authored-by: Julien <[email protected]>
  • Loading branch information
marcuspoehls and Julien-R44 authored Oct 15, 2024
1 parent ee11d9b commit e3372ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
}

Expand Down
18 changes: 18 additions & 0 deletions tests/inertia.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e3372ac

Please sign in to comment.