Skip to content

Deep Merged props get wiped on partial requests #2323

@CoolDude53

Description

@CoolDude53

Version:

  • @inertiajs/vue3 version: 2.0.8

Describe the problem:

Props with the new deepMerge feature get wiped when other deferred props load or are partially reloaded in requests that omit the deepMerge props. From reading through the client‐side merge logic, it looks like the deepMerge props are expected and merged on every request, wiping out the existing prop value instead of ignoring the empty / undefined prop value and preserving the prop's current state.

Steps to reproduce:

Route::get('/users', function () {
    $page = request()->input('page', 1);
    $per_page = request()->input('per_page', 10);

    return Inertia::render('Users/Index', [
        'results' => Inertia::defer(fn () => User::paginate($per_page, page: $page), 'results')->deepMerge(),
        'users' => Inertia::defer(fn () => User::all(), 'users'),
    ]);
});

Here, the props will be fetched in separate requests. Since the users prop will take longer to execute, the results prop will already be loaded on the client side when its request completes. The client will try to deepMerge the empty results prop in the users request, wiping the results prop value. This will also happen when making a client reload request that only asks for the users prop.

Possible Solution:

Since there already is a reset option on client side reloads, the client can ignore deepMerge props when undefined or empty in deferred requests.

cc: @HichemTab-tech

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions