Search code examples
phpreactjslaravel-8inertiajs

Some requests get canceled after redirecting to a named route


I am currently redirecting from a store route back to my index route with a flash message like this:

    public function store(StoreMemberRequest $request)
    {
        $this->authorize('create', Member::class);

        RegisterNewMember::run($request);

        return redirect()->route('admin.members.index')->with('success', 'Member successfully created');
    }

Normally this flash message shows me a notification on my frontend. I have this bit of code in my HandleInertiaRequests middleware which shares the flash data:

    public function share(Request $request)
    {
        return array_merge(parent::share($request), [
            'auth' => [
                'user' => $request->user(),
            ],
            'flash' => fn () => [
                'success' => session('success'),
                'error' => session('error'),
            ],
        ]);
    }

However, when I redirect back to my admin.members.index route the flash message is not shown. The only difference between the pages where it works and where it doesn't work is that I see that two requests are being canceled in the console:

enter image description here

More detailed information about the request (the response couldn't be loaded because no data was found):

enter image description here What could be the cause of the notification not showing? It does show on all other pages where the requests doesn't get canceled. The two canceled requests are literally the only differences that I could find. If someone needs any more detailed information than I would be happy to provide that.

Versions:

  • "@inertiajs/inertia": "^0.10.0"
  • "@inertiajs/inertia-react": "^0.7.0"
  • "inertiajs/inertia-laravel": "^0.4.5"
  • "laravel/framework": "^8.65",

Solution

  • Seems like I had some code which checked for parameters in the url on pageload. When some parameters were set the page would reload. This caused the first request to be canceled. Adding an extra check to this function solved my problem. If anyone else has the same problem, check if anywhere in your code is made a new request.