fix: department page SSR crash rendering empty body on hard reload

- Remove this. prefix from template expression in Departments/Show.vue
  (ssrRender this is undefined in strict ESM)
- Register helpers mixin in ssr.js for parity with app.js
- SafeSsrGateway: fallback to client-side render when SSR returns
  empty body or server unavailable
- Jenkins: start SSR server in background, add health check
This commit is contained in:
F4ilji
2026-10-22 12:33:20 +05:00
parent d6a55ddfbc
commit dbac7989a7
6 changed files with 107 additions and 3 deletions
Vendored
+3 -1
View File
@@ -129,7 +129,9 @@ pipeline {
sleep 5
docker exec ntspi-php php artisan inertia:stop-ssr || true
sleep 2
docker exec ntspi-php php artisan inertia:start-ssr || true
docker exec -d ntspi-php sh -c "php artisan inertia:start-ssr > /tmp/ssr-server.log 2>&1"
sleep 3
docker exec ntspi-php php artisan inertia:check-ssr || true
'''
}
}
+3
View File
@@ -45,8 +45,10 @@ use App\Services\App\Cache\SliderCacheService;
use App\Services\App\Cache\SubSectionCacheService;
use App\Ship\Contracts\SeoServiceInterface;
use App\Ship\Services\SeoPageService;
use App\Ship\Ssr\SafeSsrGateway;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Inertia\Ssr\Gateway;
use Filament\Support\Facades\FilamentView;
use Filament\Tables\View\TablesRenderHook;
use Illuminate\Database\Eloquent\Factories\Factory;
@@ -65,6 +67,7 @@ class AppServiceProvider extends ServiceProvider
public function register(): void
{
$this->app->bind(SeoServiceInterface::class, SeoPageService::class);
$this->app->bind(Gateway::class, SafeSsrGateway::class);
}
/**
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace App\Ship\Ssr;
use Exception;
use Illuminate\Http\Client\StrayRequestException;
use Illuminate\Support\Facades\Http;
use Inertia\Ssr\HttpGateway;
use Inertia\Ssr\Response;
class SafeSsrGateway extends HttpGateway
{
private bool $serverAvailable = false;
private bool $checked = false;
public function dispatch(array $page): ?Response
{
if (! $this->shouldDispatch()) {
return null;
}
if (! $this->isServerAvailable()) {
return null;
}
try {
$response = Http::timeout(5)
->retry(1, 200)
->post($this->getUrl('/render'), $page)
->throw()
->json();
} catch (Exception $e) {
if ($e instanceof StrayRequestException) {
throw $e;
}
$this->serverAvailable = false;
return null;
}
if (is_null($response)) {
return null;
}
$body = $response['body'] ?? '';
$head = $response['head'] ?? [];
if (empty($body) && empty($head)) {
return null;
}
return new Response(
implode("\n", $head),
$body
);
}
public function isHealthy(): bool
{
return $this->isServerAvailable();
}
private function isServerAvailable(): bool
{
if ($this->checked) {
return $this->serverAvailable;
}
$this->checked = true;
try {
$this->serverAvailable = Http::timeout(1)
->get($this->getUrl('/health'))
->successful();
} catch (Exception $e) {
if ($e instanceof StrayRequestException) {
throw $e;
}
$this->serverAvailable = false;
}
return $this->serverAvailable;
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
return [
'ssr' => [
'enabled' => env('INERTIA_SSR_ENABLED', true),
'url' => env('INERTIA_SSR_URL', 'http://127.0.0.1:13714'),
'ensure_bundle_exists' => env('INERTIA_SSR_ENSURE_BUNDLE_EXISTS', true),
],
'use_script_element_for_initial_page' => false,
];
@@ -16,7 +16,7 @@
<div class="flex gap-x-1">
<ul class="px-0.5 last-of-type:mb-0 mb-8">
<li v-for="depart in departments.data" :key="department.id" class="my-1.5 flex">
<a :class="{'text-white hover:text-gray-200 font-semibold bg-[#135aae]': this.IS_SAME_ROUTE(route('client.department.show', { facultySlug: department.data.faculty.slug, departmentSlug: depart.slug })), 'text-gray-600 hover:text-[#2C6288]': !this.IS_SAME_ROUTE(route('client.department.show', { facultySlug: department.data.faculty.slug, departmentSlug: depart.slug })) }"
<a :class="{'text-white hover:text-gray-200 font-semibold bg-[#135aae]': IS_SAME_ROUTE(route('client.department.show', { facultySlug: department.data.faculty.slug, departmentSlug: depart.slug })), 'text-gray-600 hover:text-[#2C6288]': !IS_SAME_ROUTE(route('client.department.show', { facultySlug: department.data.faculty.slug, departmentSlug: depart.slug })) }"
:href="route('client.department.show', { facultySlug: department.data.faculty.slug, departmentSlug: depart.slug }) + '/'"
class="relative duration-300 flex w-full rounded-md cursor-pointer items-center px-2 py-1 text-left text-sm">{{
depart.title
+3 -1
View File
@@ -59,6 +59,7 @@ import { createSSRApp, h } from 'vue'
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import { Ziggy } from './ziggy';
import { createSsrErrorHandler, logSsrError } from './ssr/errorHandler.js';
import { helpers } from './mixins/Helpers.js';
const EMPTY_RESPONSE = { head: [], body: '' };
@@ -89,7 +90,8 @@ createServer(page =>
return ssrApp
.use(plugin)
.use(ZiggyVue, ziggyConfig);
.use(ZiggyVue, ziggyConfig)
.mixin(helpers);
},
}).then(result => result ?? EMPTY_RESPONSE).catch(error => {
logSsrError(error);