fix: skip loadForms during SSR to prevent localhost fallback error

During server-side rendering main.ts never runs, so loadRuntimeConfig()
is never called and apiUrl falls back to localhost:8000. The failed HTTP
call triggers the error snackbar during client hydration. Guard loadForms
with isPlatformBrowser so it only runs in the browser where the config
is correctly loaded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vee1e 2026-06-02 13:44:34 +05:30
parent b9bf24ef71
commit 252cb503fe
No known key found for this signature in database
GPG key ID: EB498AFC60A7A01A

View file

@ -1,5 +1,5 @@
import { Component, OnInit, Input, OnChanges, SimpleChanges, HostListener } from '@angular/core'; import { Component, OnInit, Input, OnChanges, SimpleChanges, HostListener, PLATFORM_ID, inject } from '@angular/core';
import { CommonModule } from '@angular/common'; import { isPlatformBrowser, CommonModule } from '@angular/common';
import { MatCardModule } from '@angular/material/card'; import { MatCardModule } from '@angular/material/card';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon';
@ -1593,10 +1593,14 @@ export class UploadComponent implements OnInit, OnChanges {
currentPreviewedFormId: string | null = null; currentPreviewedFormId: string | null = null;
updateTargetForm: FormData | null = null; updateTargetForm: FormData | null = null;
private platformId = inject(PLATFORM_ID);
constructor(private formService: FormService, private formPreviewService: FormPreviewService, private snackBar: MatSnackBar) {} constructor(private formService: FormService, private formPreviewService: FormPreviewService, private snackBar: MatSnackBar) {}
ngOnInit(): void { ngOnInit(): void {
this.loadForms(); if (isPlatformBrowser(this.platformId)) {
this.loadForms();
}
this.restoreUploadState(); this.restoreUploadState();
// Subscribe to currently previewed form // Subscribe to currently previewed form