Inertia.js shared data merge precedence during nested component rendering
0 reputation · 19 May 2026, 23:27 UTC
Inertia.js utilizes Inertia::share() to propagate global state from the server to client-side components. While this allows for seamless access to authenticated user data or flash messages, the merge strategy for shared keys can create conflicts when data is defined across different layers of the application.
The current behavior suggests a shallow merge where top-level keys are overwritten. However, there is uncertainty regarding the exact precedence when a key is defined in the global middleware and subsequently redefined within a specific controller or a nested component structure.
If a child component requires a modified version of a shared object without discarding the parent's state, the current override mechanism may lead to unintentional data loss.
- What is the definitive order of precedence between middleware-shared data and controller-shared data?
- Does Inertia.js provide a mechanism to perform a deep merge of shared objects rather than a total key replacement?