diff --git a/src/Exceptions/Concerns/RendersControlPanelExceptions.php b/src/Exceptions/Concerns/RendersControlPanelExceptions.php index 11d746622ec..683ae3fa142 100644 --- a/src/Exceptions/Concerns/RendersControlPanelExceptions.php +++ b/src/Exceptions/Concerns/RendersControlPanelExceptions.php @@ -7,6 +7,7 @@ use Illuminate\Http\RedirectResponse; use Inertia\Inertia; use Statamic\Facades\URL; +use Statamic\Http\Middleware\CP\HandleInertiaRequests; use Statamic\Statamic; trait RendersControlPanelExceptions @@ -23,6 +24,7 @@ protected function renderException($request, $e) Statamic::$isRenderingCpException = true; return Inertia::render('errors/Error', ['status' => $response->getStatusCode()]) + ->rootView(HandleInertiaRequests::ROOT_VIEW) ->toResponse($request) ->setStatusCode($response->getStatusCode()); } diff --git a/src/Exceptions/Concerns/RendersHttpExceptions.php b/src/Exceptions/Concerns/RendersHttpExceptions.php index 53b9121c964..b983af0777d 100644 --- a/src/Exceptions/Concerns/RendersHttpExceptions.php +++ b/src/Exceptions/Concerns/RendersHttpExceptions.php @@ -9,6 +9,7 @@ use Statamic\Exceptions\AuthenticationException; use Statamic\Facades\Cascade; use Statamic\Facades\User; +use Statamic\Http\Middleware\CP\HandleInertiaRequests; use Statamic\Statamic; use Statamic\StaticCaching\Cacher; use Statamic\StaticCaching\Cachers\ApplicationCacher; @@ -30,6 +31,7 @@ public function render(Request $request) } return Inertia::render('errors/'.$this->getStatusCode()) + ->rootView(HandleInertiaRequests::ROOT_VIEW) ->toResponse(request()) ->setStatusCode($this->getStatusCode()); } diff --git a/src/Http/Middleware/CP/HandleInertiaRequests.php b/src/Http/Middleware/CP/HandleInertiaRequests.php index d385b0ee252..a8b2ab69546 100644 --- a/src/Http/Middleware/CP/HandleInertiaRequests.php +++ b/src/Http/Middleware/CP/HandleInertiaRequests.php @@ -11,7 +11,9 @@ class HandleInertiaRequests extends Middleware { - protected $rootView = 'statamic::layout'; + public const ROOT_VIEW = 'statamic::layout'; + + protected $rootView = self::ROOT_VIEW; public function version(Request $request): ?string { diff --git a/src/Providers/CpServiceProvider.php b/src/Providers/CpServiceProvider.php index 1337a22fe2b..b640613b146 100644 --- a/src/Providers/CpServiceProvider.php +++ b/src/Providers/CpServiceProvider.php @@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; -use Inertia\Inertia; use Statamic\CP\Utilities\UtilityRepository; use Statamic\Extensions\Translation\Loader; use Statamic\Extensions\Translation\Translator; @@ -21,8 +20,6 @@ class CpServiceProvider extends ServiceProvider { public function boot() { - Inertia::setRootView('statamic::layout'); - View::composer('statamic::*', function ($view) { $view->with('user', User::current()); }); diff --git a/tests/Feature/InertiaRootViewTest.php b/tests/Feature/InertiaRootViewTest.php new file mode 100644 index 00000000000..79ede48e543 --- /dev/null +++ b/tests/Feature/InertiaRootViewTest.php @@ -0,0 +1,19 @@ +toResponse(Request::create('/')); + + $this->assertEquals('app', $response->getOriginalContent()->name()); + } +} diff --git a/tests/__fixtures__/views/app.blade.php b/tests/__fixtures__/views/app.blade.php new file mode 100644 index 00000000000..4713df4a786 --- /dev/null +++ b/tests/__fixtures__/views/app.blade.php @@ -0,0 +1 @@ +