Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Automatic page reload after Inertia::post / put ?

Hello,

I have a table and a modal window.

I just noticed that my app automatically reloads the page after a post or put request. The controller doesn't redirect or reload anything, it's just to save or update and nothing more.

That's not usual to have this behavior.

What could be the origin ?

Do you have any idea ?

Thanks for your help.

V

0 likes
8 replies
rodrigo.pedra's avatar
Level 56

That's not usual to have this behavior.

That is actually the expected behavior when making manual requests using Inertia.

Inertia::post or Inertia::put both expect a Inertia response. Either a redirect, or a page object.

All requests made trough inertia, even through their form helper, actually expect an inertia response.

It is in their docs:

https://inertiajs.com/the-protocol#html-responses

If you are not returning anything explicit, an empty response is generated, and the laravel inertia adapter converts an empty response to a redirect->back() call, thus reloading the page:

https://github.com/inertiajs/inertia-laravel/blob/540b953ec383364264f9bd633849db16560a4461/src/Middleware.php#L122-L125

It seems you want to make a POST/PUT request and decide in your JS code the behavior after a successful response without having inertia doing its magic for you.

This is fine in an inertia application, for example in user settings page where one want to save a checkbox state without reloading the page.

The recommendation, from the inertia docs is to do it manually, either by using axios, fetch, XMLHttpRequest:

https://inertiajs.com/forms#xhr-fetch-submissions

The idea of using inertia helpers is to have a SPA like application but using traditional server-side paradigms, such as server-side routing and validation.

What you seem to be wanting is to make an AJAX update, so the bottom line is that you need to handle this yourself outside of inertia.

3 likes
vincent15000's avatar

@rodrigo.pedra Thank you for the very detailed answer.

I had already read that every Inertia request expects an Inertia response, but I didn't read that there's an automatic redirect->back if there is no explicit Inertia response in the controller.

Effectively I want to do a simple ajax request and I wanted to test using Inertia::post without returning any response and I have been surprised that the page has automatically reloaded.

So if I need to do an ajax request, you suggest me better to use fetch or axios rather than Inertia::post without response.

That's exactly what I initially had and I tried to transform the code to use Inertia requests only, what is probably not the best idea. I experiment Inertia yet.

Thank you very much for your help ;).

2 likes
rodrigo.pedra's avatar

@vincent15000

You are welcome!

So if I need to do an ajax request, you suggest me better to use fetch or axios rather than Inertia::post without response.

Yes. To be frank I also discovered this with surprise some time ago.

Have a nice day =)

1 like
Sinnbeck's avatar

Be aware that the auto redirect was added as the old default was an empty response which resulted in a white modal

1 like

Please or to participate in this conversation.