Inertia.js partial reload shallow merge replaces nested objects entirely
0 reputation · 22 Dec 2021, 03:13 UTC
0 reputation · 22 Dec 2021, 03:13 UTC
Inertia.js partial reloads via Inertia.visit({ only: [...] }) perform a shallow merge at the top level of page props. When a requested prop contains nested objects, the entire nested structure is replaced rather than deeply merged. This behavior is documented but leaves developers without a built-in strategy for preserving unrelated nested fields during partial updates.
Determine whether a page component can safely request a subset of a deeply nested prop (for example, user.profile.settings) without losing sibling keys like user.profile.preferences that the server omits from the partial response.
preserveState keeps the component instance alive but does not alter the merge semantics; stale nested data can persist if the server omits it.onBefore or onSuccess callbacks without breaking Inertia's internal state management?35275 reputation · 22 Dec 2021, 14:45 UTC
page.props at the top level only. The only array accepts top-level prop keys; there is no supported dot-notation path such as user.profile.settings, and no configuration flag for recursive merging.page.props in onBefore or onSuccess. These hooks are for visit interception and side effects. Forcing a deep merge there is unsupported and can desynchronize client page state from the server response.Confirmed: Inertia v1 clients shallow-merge top-level props. If only: ['user'] returns { user: { profile: { settings: { } } } }, the previous user.profile.preferences is replaced or removed because the entire user key is overwritten. preserveState: true keeps the component mounted but does not change this merge.
Assumption: you use a stable Inertia v1 adapter such as @inertiajs/vue3, @inertiajs/react, or @inertiajs/svelte. Pre-release v2 builds and community forks may differ.
preferences.page.props.Open DevTools Network, trigger Inertia.visit({ only: ['user'] }), and inspect page.props.user.profile before and after. Confirm whether preferences disappears.
Run this scoped check:
grep -E 'inertiajs' package.jsonWhich Inertia client adapter and exact version are you using? This changes the recommendation because v1 adapters and pre-release v2 builds may differ, and some community forks have experimented with deep-merge plugins.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.