fix(ssr): fetch station config during server-side rendering #10

Merged
kfj001 merged 1 commits from bugfix/ssr-fetch-config-on-server into main 2026-08-08 08:03:53 -07:00
Member

Problem

After PR #9 (SSR infrastructure), the SSR server was running correctly but still rendered DEFAULT_CONFIG (hardcoded colors, assets, content) instead of real DB values. Users saw stale defaults on every initial paint.

Root Cause

The isPlatformBrowser guard in App.ngOnInit() exited early on the server, so stationConfig.load() never ran during SSR. The SSR infrastructure was working (nginx proxying to Node server correctly) — the app code just never fetched the config.

Fix

Two-part fix:

  1. main.server.ts: Added an APP_INITIALIZER that blocks server rendering until stationConfig.load() resolves. Uses isPlatformServer so it only blocks on the server — is a no-op in the browser to avoid blocking the client.

  2. app.ts: Moved stationConfig.load() before the isPlatformBrowser guard so ngOnInit also fetches config on the server as a safety net.

Result

SSR HTML now contains real DB values (colors, hero icon, station name, etc.) instead of build-time defaults — eliminating the stale-asset flash reported by users.

Files Changed

  • src/main.server.ts — Added APP_INITIALIZER for server-side config fetch
  • src/app/app.ts — Moved stationConfig.load() before isPlatformBrowser guard
## Problem After PR #9 (SSR infrastructure), the SSR server was running correctly but still rendered `DEFAULT_CONFIG` (hardcoded colors, assets, content) instead of real DB values. Users saw stale defaults on every initial paint. ## Root Cause The `isPlatformBrowser` guard in `App.ngOnInit()` exited early on the server, so `stationConfig.load()` never ran during SSR. The SSR infrastructure was working (nginx proxying to Node server correctly) — the app code just never fetched the config. ## Fix Two-part fix: 1. **`main.server.ts`**: Added an `APP_INITIALIZER` that blocks server rendering until `stationConfig.load()` resolves. Uses `isPlatformServer` so it only blocks on the server — is a no-op in the browser to avoid blocking the client. 2. **`app.ts`**: Moved `stationConfig.load()` before the `isPlatformBrowser` guard so `ngOnInit` also fetches config on the server as a safety net. ## Result SSR HTML now contains real DB values (colors, hero icon, station name, etc.) instead of build-time defaults — eliminating the stale-asset flash reported by users. ## Files Changed - `src/main.server.ts` — Added APP_INITIALIZER for server-side config fetch - `src/app/app.ts` — Moved stationConfig.load() before isPlatformBrowser guard
robot added 1 commit 2026-08-08 05:10:31 -07:00
fix(ssr): fetch station config during server-side rendering
CI Pipeline / backend-test (push) Successful in 5m18s
CI Pipeline / frontend-test (push) Successful in 23s
CI Pipeline / frontend-build (push) Successful in 29s
CI Pipeline / backend-lint (push) Successful in 7s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
CI Pipeline / backend-test (pull_request) Successful in 5m14s
CI Pipeline / frontend-test (pull_request) Successful in 22s
CI Pipeline / frontend-build (pull_request) Successful in 29s
CI Pipeline / backend-lint (pull_request) Successful in 8s
54bd869042
The isPlatformBrowser guard in App.ngOnInit() was blocking
stationConfig.load() on the server, so SSR always rendered with
DEFAULT_CONFIG (hardcoded colors, assets, content).

Two-part fix:
- main.server.ts: Add APP_INITIALIZER that blocks server rendering
  until station config is fetched from the API. Only runs on the
  server — is a no-op in the browser to avoid blocking the client.
- app.ts: Move stationConfig.load() before the isPlatformBrowser
  guard so ngOnInit also calls it on the server as a safety net.

This ensures SSR HTML contains real DB values (colors, hero icon,
station name, etc.) instead of build-time defaults — eliminating
the stale-asset flash reported by users.
robot force-pushed bugfix/ssr-fetch-config-on-server from c0b538a7cc to 54bd869042 2026-08-08 05:10:31 -07:00 Compare
kfj001 approved these changes 2026-08-08 08:03:43 -07:00
kfj001 merged commit 96011ef200 into main 2026-08-08 08:03:53 -07:00
kfj001 deleted branch bugfix/ssr-fetch-config-on-server 2026-08-08 08:03:53 -07:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: WesternTechnologies/kmtnflower#10