Skip to content

Fix Undefined property: Inertia\Response::$headers #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SuperDJ
Copy link
Contributor

@SuperDJ SuperDJ commented Apr 7, 2025

Fix #113

@pascalbaljet
Copy link
Contributor

What I don't understand is, given that Inertia\Response implements Responsable, why isn't toResponse() called after the then() callback in the first place?

@pascalbaljet pascalbaljet added the needs more info Incomplete issue or more info requested label Apr 8, 2025
@SuperDJ
Copy link
Contributor Author

SuperDJ commented Apr 8, 2025

@pascalbaljet tried adding a test to reproduce the errors. When seeing the error it's always when redirecting from one page to a modal page that has a baseRoute that is different from the redirecting page. Lets say from index your redirect to users.edit (a modal) with a baseRoute of users.show. If that isn't giving you any errors, it might be a conflict between used packages. For example stancl/tenancy is used but might conflict.

@SuperDJ
Copy link
Contributor Author

SuperDJ commented Apr 9, 2025

@pascalbaljet if it helps these are the gathered middleware:

image

taken from dd($this->gatherMiddleware($route));

@SuperDJ
Copy link
Contributor Author

SuperDJ commented Apr 9, 2025

@pascalbaljet is the DispatchBaseUrlRequest supposed to run multiple times? In the error it runs once and passes the Inertia\Middleware
image

at a later stage it fails to pass Inertia\Middleware due to the error
image

@ndijkstra
Copy link

I'm having the same issue since 0.20.1. This is also in combination the tenancy package

@SuperDJ
Copy link
Contributor Author

SuperDJ commented May 12, 2025

@ndijkstra does my proposed fix work for you as well?

@ndijkstra
Copy link

Yes, it will solve the error about the $headers. But sending data with a reload is still not working for me, but not sure if this issue is related

@SuperDJ
Copy link
Contributor Author

SuperDJ commented May 13, 2025

@ndijkstra you mean with a partial reload? I haven't tested that. Does that throw an error with the $headers as well?

@ndijkstra
Copy link

@ndijkstra you mean with a partial reload? I haven't tested that. Does that throw an error with the $headers as well?

My partial reload error is not related to this error. Your PR will solve the issue related to the $headers exception

@SuperDJ
Copy link
Contributor Author

SuperDJ commented May 23, 2025

If someone is interested, a temporary package with this fix applied is available here.

@pascalbaljet
Copy link
Contributor

I've investigated this PR and the issue (#113) once more, and I still can't figure out the problem. Also, the newly added test makes the wrong assertion:

$response = $this->from('/users/'.$user->id)
    ->get('/users/'.$user->id.'/edit');

$response->assertOk()
    ->assertInertia(fn (AssertableInertia $page) => $page
        ->component('ShowUser')
        ->url('/users/'.$user->id.'/edit')
        ->has('_inertiaui_modal', fn (AssertableInertia $assert) => $assert
            // ...
            ->where('baseUrl', '/users')
        )
    );
}

The baseUrl should be '/users/'.$user->id since that's the page from which you're requesting the modal. The component assertion (ShowUser) is correct, though, so the baseUrl and component contradict.

Would it be possible to add a (failing) Dusk test for this? That would make it a bit more visual to see what's happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Incomplete issue or more info requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined property: Inertia\Response::$headers in inertia-laravel/Middleware
3 participants