hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { RouterProvider } from "@tanstack/solid-router"; |
| 2 | import { ErrorBoundary, Suspense, lazy } from "solid-js"; |
| 3 | import { currentLocale, formatApiError } from "@/api/client"; |
| 4 | import { IconAlert } from "@/components/ui/icons"; |
| 5 | import { router } from "@/routes/router"; |
| 6 | |
| 7 | const RouterDevtools = import.meta.env.DEV ? lazy(() => import("@/router-devtools")) : undefined; |
| 8 | |
| 9 | // A deploy can invalidate a lazy route chunk while an older tab is still |
| 10 | // open. Vite exposes this event for exactly that case; reload once so the |
| 11 | // browser gets the new index.html and its matching chunk manifest. |
| 12 | if (typeof window !== "undefined") { |
| 13 | window.addEventListener("vite:preloadError", (event) => { |
| 14 | event.preventDefault(); |
| 15 | const reloadKey = "hezarfen:chunk-reload"; |
| 16 | if (sessionStorage.getItem(reloadKey) === "1") { |
| 17 | sessionStorage.removeItem(reloadKey); |
| 18 | return; |
| 19 | } |
| 20 | sessionStorage.setItem(reloadKey, "1"); |
| 21 | window.location.reload(); |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | // Last-resort backstop for anything that throws during render. It lives above |
| 26 | // the i18n provider, so it mirrors the client's own bilingual-fallback idiom |
| 27 | // instead of using t(...); a real message + reload beats a blank document. |
| 28 | function RootErrorFallback(props: { error: unknown; reset: () => void }) { |
| 29 | const tr = currentLocale() === "tr"; |
| 30 | // Keep the raw error + stack in the console; the box only shows a friendly |
| 31 | // one-liner, so without this the actual throw (e.g. a transient render error) |
| 32 | // is lost and impossible to trace after the fact. |
| 33 | console.error("Uncaught render error:", props.error); |
| 34 | return ( |
| 35 | <div class="flex min-h-[var(--app-viewport)] items-center justify-center bg-background px-4"> |
| 36 | <div class="w-full max-w-[420px] space-y-5 rounded-xl border border-border-line bg-surface-base p-8 text-center shadow-[0_10px_24px_-4px_rgba(0,0,0,0.10)]"> |
| 37 | <div class="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10 text-destructive-text"> |
| 38 | <IconAlert class="h-6 w-6" /> |
| 39 | </div> |
| 40 | <div class="space-y-2"> |
| 41 | <p class="text-4xl font-semibold tracking-tight text-text-strong">500</p> |
| 42 | <p class="text-sm leading-[21px] text-text-subtle">{formatApiError(props.error)}</p> |
| 43 | </div> |
| 44 | <button |
| 45 | type="button" |
| 46 | class="inline-flex h-9 items-center justify-center gap-1.5 rounded-lg bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90" |
| 47 | onClick={() => { |
| 48 | props.reset(); |
| 49 | window.location.reload(); |
| 50 | }} |
| 51 | > |
| 52 | {tr ? "Yeniden yükle" : "Reload"} |
| 53 | </button> |
| 54 | </div> |
| 55 | </div> |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | export function App() { |
| 60 | return ( |
| 61 | <ErrorBoundary fallback={(error, reset) => <RootErrorFallback error={error} reset={reset} />}> |
| 62 | <RouterProvider router={router} /> |
| 63 | {RouterDevtools ? ( |
| 64 | <Suspense> |
| 65 | <RouterDevtools /> |
| 66 | </Suspense> |
| 67 | ) : null} |
| 68 | </ErrorBoundary> |
| 69 | ); |
| 70 | } |