refactor(status-page): simplify renderer lookup, extract route prefix, memoize wrapper style

Four small follow-ups from a code review pass:

1. Drop the redundant `?? THEMED_RENDERERS[DEFAULT_STATUS_PAGE_THEME]`
   fallback in Status/index.tsx — the map is now a total Record, so the
   first lookup cannot return undefined.
2. Extract the literal "/status/public" into PUBLIC_STATUS_PAGE_PREFIX in
   Types/StatusPage.ts and reuse from the three runtime call sites
   (Status/index.tsx, HeaderStatusPageControls.tsx, StatusPagesTable.tsx).
   The Routes/index.tsx route definition keeps its string literal — the
   route table is otherwise all literals and the prefix only matters when
   it's interpolated.
3. Delete two narrating comments above the public/admin branches in
   Status/index.tsx — the JSX is self-describing.
4. Move the inline `style` object construction in StatusPageThemeProvider
   into the existing useMemo so the wrapper div receives a stable style
   reference. The previous spread defeated the surrounding memoization on
   every render.
This commit is contained in:
gorkem-bwl committed 2026-04-28 16:52:16 -04:00
1 parent ed3645c3d0
commit bab65770ce
5 files changed
+22 -21

No files matched your search

+4 -7
View File
@@ -11,6 +11,7 @@ import { useGet } from "@/Hooks/UseApi";
import type { Monitor } from "@/Types/Monitor";
import {
DEFAULT_STATUS_PAGE_THEME,
PUBLIC_STATUS_PAGE_PREFIX,
type StatusPage,
type StatusPageResponse,
type StatusPageTheme,
@@ -44,7 +45,7 @@ const StatusPageView = () => {
const { url } = useParams();
const isAdmin = useIsAdmin();
const location = useLocation();
const isPublic = location.pathname.startsWith("/status/public");
const isPublic = location.pathname.startsWith(PUBLIC_STATUS_PAGE_PREFIX);
const apiUrl = url ? `/status-page/${url}?type=uptime&type=infrastructure` : null;
@@ -88,9 +89,7 @@ const StatusPageView = () => {
);
}
const ThemedRenderer =
THEMED_RENDERERS[statusPage.theme ?? DEFAULT_STATUS_PAGE_THEME] ??
THEMED_RENDERERS[DEFAULT_STATUS_PAGE_THEME];
const ThemedRenderer = THEMED_RENDERERS[statusPage.theme ?? DEFAULT_STATUS_PAGE_THEME];
const themedRenderer = (
<ThemedRenderer
statusPage={statusPage}
@@ -98,7 +97,6 @@ const StatusPageView = () => {
/>
);
// Public route: render directly on the viewport, themed background covers everything.
if (isPublic) {
return (
<StatusPageThemeProvider
@@ -111,8 +109,7 @@ const StatusPageView = () => {
);
}
// Admin preview: wrap in a mock browser frame inside the admin shell.
const publicUrl = `${window.location.origin}/status/public/${statusPage.url}`;
const publicUrl = `${window.location.origin}${PUBLIC_STATUS_PAGE_PREFIX}/${statusPage.url}`;
return (
<BasePage
loading={isLoading}