Skip to content

Commit

Permalink
fix: ssr errors (#372)
Browse files Browse the repository at this point in the history
* fix: ssr errors on error pages

* fix: window can't be accessed in ssr mode
  • Loading branch information
andreiio authored Jun 14, 2024
1 parent 6cf1f70 commit 252b804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Exceptions;

use App\Http\Middleware\HandleInertiaRequests;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Inertia\Inertia;
use Throwable;
Expand Down Expand Up @@ -38,6 +39,9 @@ public function render($request, Throwable $e)
$response = parent::render($request, $e);

if (! app()->isLocal() && \in_array($response->status(), [401, 403, 404, 429, 500, 503])) {
// This fixes SSR errors on error pages.
Inertia::share((new HandleInertiaRequests)->share($request));

return Inertia::render('Error', [
'status' => $response->status(),
'title' => __('error.' . $response->status() . '.title'),
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ const navigation = [
];
const isActive = (item) => {
if (item.route === `${window.location.origin}${window.location.pathname}${window.location.search}`) {
return true;
if (typeof window === 'undefined') {
return false;
}
return false;
return item.route === `${window.location.origin}${window.location.pathname}${window.location.search}`;
};
</script>

0 comments on commit 252b804

Please sign in to comment.