inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
1.99k stars 222 forks source link

[1.x] Fix shared dot props #634

Closed RobertBoes closed 1 month ago

RobertBoes commented 1 month ago

I think #620 introduced a breaking change when sharing props through the middleware, as described in #633

A use-case would be the following:

class HandleInertiaRequests extends Middleware
{
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
            'user.verified' => true,
        ]);
    }
}

Then render the page using:

Inertia::render('User/Show', [
    'user' => [
        'name' => 'John',
    ],
]);

This would result in just props: { user: { name: 'John' }} being sent to the frontend instead of props: { user: { name: 'John', verified: true }}, with this PR the latter would happen.

I attempted to fix the issue by merging the props instead of overwriting them. However, I'm not actually sure why this feature worked before, since it seems like props were always overwritten.

VicGUTT commented 1 month ago

Hey @RobertBoes, without looking to deep into it and although that was not the intended fix of my PR, I was wondering if my PR #631 doesn't also resolve the issue described here?

The point of my PR was to simply revert back the order of which property instances and arrayable properties were resolved prior to #620.