From 917d58397ae65955b175d43bad5a2f0993aac724 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 21 Oct 2026 16:11:32 -0400 Subject: [PATCH] Fix CP downloads over Inertia requests with inertia-laravel 3.5.2 inertia-laravel 3.5.2 no longer passes streamed and binary file responses to onEmptyResponse, so downloads were no longer converted into location visits. Convert them before the parent middleware handles the response, which works across all supported versions. Co-Authored-By: Claude Opus 5.5 --- .../Middleware/CP/HandleInertiaRequests.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Http/Middleware/CP/HandleInertiaRequests.php b/src/Http/Middleware/CP/HandleInertiaRequests.php index 19a75c61777..8844abc60a9 100644 --- a/src/Http/Middleware/CP/HandleInertiaRequests.php +++ b/src/Http/Middleware/CP/HandleInertiaRequests.php @@ -2,9 +2,11 @@ namespace Statamic\Http\Middleware\CP; +use Closure; use Illuminate\Http\Request; use Inertia\Inertia; use Inertia\Middleware; +use Inertia\Support\Header; use Statamic\CP\Toasts\Manager; use Statamic\Statamic; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -42,13 +44,22 @@ public function share(Request $request): array ]); } - public function onEmptyResponse(Request $request, Response $response): Response + public function handle(Request $request, Closure $next) { - if ($response instanceof StreamedResponse || $response instanceof BinaryFileResponse) { - return Inertia::location($request->fullUrl()); - } + return parent::handle($request, function ($request) use ($next) { + $response = $next($request); + + if ($request->header(Header::INERTIA) && $this->isDownload($response)) { + return Inertia::location($request->fullUrl()); + } - return parent::onEmptyResponse($request, $response); + return $response; + }); + } + + private function isDownload(Response $response): bool + { + return $response instanceof StreamedResponse || $response instanceof BinaryFileResponse; } private function logos()