From f830d10c68a8bcd03905e077e11a7c7307ac28eb Mon Sep 17 00:00:00 2001
From: nexy7574 <git@nexy7574.co.uk>
Date: Mon, 13 Jan 2025 16:55:32 +0000
Subject: [PATCH] Load configurations in parallel & stop suppressing errors

correct commit this time
---
 src/app/components/ClientConfigLoader.tsx | 31 ++++++++++-------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/app/components/ClientConfigLoader.tsx b/src/app/components/ClientConfigLoader.tsx
index 73250751..5fe13c1c 100644
--- a/src/app/components/ClientConfigLoader.tsx
+++ b/src/app/components/ClientConfigLoader.tsx
@@ -4,26 +4,21 @@ import { ClientConfig } from '../hooks/useClientConfig';
 import { trimTrailingSlash } from '../utils/common';
 
 const getClientConfig = async (): Promise<ClientConfig> => {
-  let url = `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.${window.location.hostname}.json`;
-  let config = await fetch(url, { method: 'GET' });
+  const defaultConfig = fetch(
+    `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.json`, { method: 'GET' }
+  );
+  const perSiteConfig = fetch(
+    `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.${window.location.hostname}.json`, { method: "GET" }
+  );
 
-  let loadedConfig = null;
-  try {
-    if(config.ok && import.meta.env.MODE != "development") {
-      loadedConfig = await config.json();
+  return perSiteConfig.then(
+    async (pscResponse) => {
+      if (import.meta.env.MODE === "development" || !pscResponse.ok) {
+        return defaultConfig.then((dcResponse) => dcResponse.json());
+      }
+      return pscResponse.json();
     }
-  } catch (e) {}
-
-  if(!loadedConfig) {
-    url = `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.json`;
-    config = await fetch(url, { method: 'GET' });
-    try {
-      loadedConfig = await config.json();
-    } catch (e) {
-      return {};
-    }
-  }
-  return loadedConfig;
+  )
 };
 
 type ClientConfigLoaderProps = {