diff --git a/src/presentation/boundaries/chunk-recovery-boundary.tsx b/src/presentation/boundaries/chunk-recovery-boundary.tsx index 5f9cb8e2..8cc8e375 100644 --- a/src/presentation/boundaries/chunk-recovery-boundary.tsx +++ b/src/presentation/boundaries/chunk-recovery-boundary.tsx @@ -3,7 +3,7 @@ import { type ErrorInfo, type ReactNode, } from "react"; -import { Button } from "../design-system/index.ts"; +import { Button, LoadingSurface } from "../design-system/index.ts"; import { useLocale } from "../i18n/index.ts"; type RecoveryResult = @@ -99,9 +99,9 @@ function ChunkRecoverySurface({ const { message } = useLocale(); if (recovery === "checking") { return ( -
- {message("chunk.checking")} -
+
+ +
); } if (recovery === "reload-requested") { diff --git a/src/presentation/components/async-surface.tsx b/src/presentation/components/async-surface.tsx index f172014c..ee494478 100644 --- a/src/presentation/components/async-surface.tsx +++ b/src/presentation/components/async-surface.tsx @@ -6,9 +6,13 @@ import { useLocale } from "../i18n/index.ts"; import { errorMessage } from "./error-copy.ts"; import { Button } from "./ui/button.ts"; -export function LoadingSurface({ label }: Readonly<{ label?: string }>) { +export function LoadingSurface({ + label, + description, +}: Readonly<{ label?: string; description?: string }>) { const { message } = useLocale(); - const accessibleLabel = label ?? message("async.loading"); + // Visible copy doubles as the name unless a separate label is given. + const accessibleLabel = label ?? description ?? message("async.loading"); return (
) { aria-atomic="true" >
); } diff --git a/src/presentation/examples/auth-example-page.tsx b/src/presentation/examples/auth-example-page.tsx index aa7a1b37..41e2b1ca 100644 --- a/src/presentation/examples/auth-example-page.tsx +++ b/src/presentation/examples/auth-example-page.tsx @@ -1,26 +1,12 @@ -import { useState } from "react"; -import { useLocation } from "react-router-dom"; - import { PageHeader } from "../design-system/index.ts"; -import { useSession } from "../providers/session-provider.tsx"; +import { + useSession, + useSessionAction, +} from "../providers/session-provider.tsx"; export default function AuthExamplePage() { - const location = useLocation(); - const { sessionState, beginSignIn, signOut, recover } = useSession(); - const [pending, setPending] = useState(false); - const [failed, setFailed] = useState(false); - - async function execute(action: () => Promise): Promise { - setPending(true); - setFailed(false); - try { - await action(); - } catch { - setFailed(true); - } finally { - setPending(false); - } - } + const { sessionState } = useSession(); + const { pending, failed, run } = useSessionAction(); return (
@@ -41,11 +27,7 @@ export default function AuthExamplePage() { className="ui-button" type="button" disabled={pending || sessionState === "integration-failed"} - onClick={() => - void execute(() => - beginSignIn(`${location.pathname}${location.search}`), - ) - } + onClick={() => run("sign-in")} > 로그인 시작 @@ -53,7 +35,7 @@ export default function AuthExamplePage() { className="ui-button ui-button--secondary" type="button" disabled={pending || sessionState !== "authenticated"} - onClick={() => void execute(signOut)} + onClick={() => run("sign-out")} > 로그아웃 @@ -61,7 +43,7 @@ export default function AuthExamplePage() { className="ui-button ui-button--secondary" type="button" disabled={pending || sessionState !== "recovery-pending"} - onClick={() => void execute(recover)} + onClick={() => run("recover")} > 세션 복구 diff --git a/src/presentation/examples/platform-overview-page.tsx b/src/presentation/examples/platform-overview-page.tsx index bc950363..0c4e73f3 100644 --- a/src/presentation/examples/platform-overview-page.tsx +++ b/src/presentation/examples/platform-overview-page.tsx @@ -281,14 +281,19 @@ function buildOperationRows(): readonly OperationRow[] { export default function PlatformOverviewPage() { const runtime = useApplicationRuntime(); const [release, setRelease] = useState< - Awaited> | null + Awaited> | "failed" | null >(null); useEffect(() => { let active = true; - void runtime.getReleaseSummary().then((summary) => { - if (active) setRelease(summary); - }); + runtime.getReleaseSummary().then( + (summary) => { + if (active) setRelease(summary); + }, + () => { + if (active) setRelease("failed"); + }, + ); return () => { active = false; }; @@ -325,7 +330,9 @@ export default function PlatformOverviewPage() {

- {release ? ( + {release === "failed" ? ( + + ) : release ? ( <> diff --git a/src/presentation/layouts/app-shell.tsx b/src/presentation/layouts/app-shell.tsx index 6ba47f63..cf6336da 100644 --- a/src/presentation/layouts/app-shell.tsx +++ b/src/presentation/layouts/app-shell.tsx @@ -21,7 +21,10 @@ import { type MessageKey, } from "../i18n/index.ts"; import { useApplicationRuntime } from "../providers/application-provider.tsx"; -import { useSession } from "../providers/session-provider.tsx"; +import { + useSession, + useSessionAction, +} from "../providers/session-provider.tsx"; import { useTheme } from "../providers/theme-provider.tsx"; const SESSION_MESSAGE_KEYS = Object.freeze({ @@ -33,38 +36,17 @@ const SESSION_MESSAGE_KEYS = Object.freeze({ export function AppShell() { const location = useLocation(); - const { sessionState, beginSignIn, signOut, recover } = useSession(); + const { sessionState } = useSession(); + const sessionAction = useSessionAction(); const { preference, setPreference } = useTheme(); const { locale, setLocale, message } = useLocale(); const [navigationOpen, setNavigationOpen] = useState(false); const navigationTriggerRef = useRef(null); - const [sessionActionPending, setSessionActionPending] = useState(false); - const [sessionActionFailed, setSessionActionFailed] = useState(false); useEffect(() => { setNavigationOpen(false); }, [location.pathname]); - async function runSessionAction() { - setSessionActionPending(true); - setSessionActionFailed(false); - try { - if (sessionState === "authenticated") { - await signOut(); - } else if (sessionState === "recovery-pending") { - await recover(); - } else { - await beginSignIn( - `${location.pathname}${location.search}${location.hash}`, - ); - } - } catch { - setSessionActionFailed(true); - } finally { - setSessionActionPending(false); - } - } - const sessionActionLabel = sessionState === "authenticated" ? message("action.signOut") @@ -128,17 +110,25 @@ export function AppShell() { {integrationAvailable ? ( ) : null} - {sessionActionFailed ? ( + {sessionAction.failed ? (

{message("shell.session.actionFailed")}

diff --git a/src/presentation/pages/home-page.tsx b/src/presentation/pages/home-page.tsx index 6dfeab71..3412ffa2 100644 --- a/src/presentation/pages/home-page.tsx +++ b/src/presentation/pages/home-page.tsx @@ -23,14 +23,19 @@ const READINESS_ITEMS = Object.freeze([ export default function HomePage() { const runtime = useApplicationRuntime(); const [release, setRelease] = useState< - Awaited> | null + Awaited> | "failed" | null >(null); useEffect(() => { let active = true; - void runtime.getReleaseSummary().then((summary) => { - if (active) setRelease(summary); - }); + runtime.getReleaseSummary().then( + (summary) => { + if (active) setRelease(summary); + }, + () => { + if (active) setRelease("failed"); + }, + ); return () => { active = false; }; @@ -52,9 +57,11 @@ export default function HomePage() { ))}

- {release - ? `빌드 ${release.buildId} · 릴리스 ${release.releaseId}` - : "검증된 런타임 정보를 확인하고 있습니다."} + {release === "failed" + ? "런타임 정보를 확인하지 못했습니다." + : release + ? `빌드 ${release.buildId} · 릴리스 ${release.releaseId}` + : "검증된 런타임 정보를 확인하고 있습니다."}

diff --git a/src/presentation/pages/not-found-page.tsx b/src/presentation/pages/not-found-page.tsx index b59836ca..c75a8a3c 100644 --- a/src/presentation/pages/not-found-page.tsx +++ b/src/presentation/pages/not-found-page.tsx @@ -1,22 +1,21 @@ -import { Link } from "react-router-dom"; - import { routePath } from "../../features/installed-feature-contracts.ts"; -import { PageHeader } from "../design-system/index.ts"; +import { StatusPage } from "../design-system/index.ts"; import { useLocale } from "../i18n/index.ts"; export default function NotFoundPage() { const { message } = useLocale(); return ( -
- -
- - {message("action.goHome")} - -
-
+ ); } diff --git a/src/presentation/providers/session-provider.tsx b/src/presentation/providers/session-provider.tsx index b87129e6..8fafa3d8 100644 --- a/src/presentation/providers/session-provider.tsx +++ b/src/presentation/providers/session-provider.tsx @@ -2,9 +2,11 @@ import { createContext, useContext, useMemo, + useState, useSyncExternalStore, type ReactNode, } from "react"; +import { useLocation } from "react-router-dom"; import type { ApplicationApi, @@ -53,3 +55,36 @@ export function useSession(): SessionContextValue { } return session; } + +export type SessionAction = "sign-in" | "sign-out" | "recover"; + +/** + * One session action at a time, with the pending and failed state every + * session button shows. Sign-in returns to the current URL, hash included. + */ +export function useSessionAction(): Readonly<{ + pending: boolean; + failed: boolean; + run(action: SessionAction): void; +}> { + const { pathname, search, hash } = useLocation(); + const { beginSignIn, signOut, recover } = useSession(); + const [pending, setPending] = useState(false); + const [failed, setFailed] = useState(false); + + async function execute(action: SessionAction): Promise { + setPending(true); + setFailed(false); + try { + if (action === "sign-out") await signOut(); + else if (action === "recover") await recover(); + else await beginSignIn(`${pathname}${search}${hash}`); + } catch { + setFailed(true); + } finally { + setPending(false); + } + } + + return { pending, failed, run: (action) => void execute(action) }; +} diff --git a/src/presentation/routes/app-router.tsx b/src/presentation/routes/app-router.tsx index c21fa07d..f0960f8d 100644 --- a/src/presentation/routes/app-router.tsx +++ b/src/presentation/routes/app-router.tsx @@ -41,7 +41,7 @@ import { } from "../boundaries/chunk-recovery-boundary.tsx"; import { ContextErrorBoundary } from "../../platform/errors/context-error-boundary.tsx"; import { FeatureErrorBoundary } from "../../platform/errors/feature-error-boundary.tsx"; -import { Button, PageHeader } from "../design-system/index.ts"; +import { LoadingSurface, StatusPage } from "../design-system/index.ts"; import { useLocale } from "../i18n/index.ts"; import { AppShell } from "../layouts/app-shell.tsx"; import { @@ -49,7 +49,11 @@ import { useApplicationRecovery, useApplicationRuntime, } from "../providers/application-provider.tsx"; -import { SessionProvider, useSession } from "../providers/session-provider.tsx"; +import { + SessionProvider, + useSession, + useSessionAction, +} from "../providers/session-provider.tsx"; import { createRedirectLoopGuard, decideRouteAccess, @@ -63,22 +67,24 @@ import { ROUTE_RUNTIME } from "../../features/installed-feature-runtimes.tsx"; import type { ParsedRouteInput } from "./route-contract.ts"; import { RouteInputProvider } from "./route-input.tsx"; -function RouteLoadingSurface({ definition }: { definition: RouteDefinition }) { +/** Route-level loading: the shared LoadingSurface inside the page frame. */ +function RouteLoadingSurface({ + definition, +}: Readonly<{ definition?: RouteDefinition }>) { const { message, resolve } = useLocale(); - const title = resolve(`route.${definition.routeId}.title`); return ( -
-
+
+ +
); } @@ -89,28 +95,30 @@ function RouteFailureSurface({ }) { const { message } = useLocale(); return ( -
- -
+ ); } function InvalidRouteSurface({ code }: { code: string }) { const { message } = useLocale(); return ( -
- +

{message("route.invalid.action")}

-
+
); } @@ -122,15 +130,18 @@ function InvalidRouteSurface({ code }: { code: string }) { function DisabledFeatureSurface({ featureId }: { featureId: string }) { const { message } = useLocale(); return ( -
- +

{message("route.disabledFeature.action")}

-
+
); } @@ -200,73 +211,57 @@ function ProtectedRoute({ routeId: RouteId; children: ReactNode; }) { - const location = useLocation(); - const { sessionState, beginSignIn, recover } = useSession(); + const { sessionState } = useSession(); const { message } = useLocale(); - const [pending, setPending] = useState(false); - const [failed, setFailed] = useState(false); + const { pending, failed, run } = useSessionAction(); const decision = decideRouteAccess(routeId, sessionState); - async function continueSession() { - setPending(true); - setFailed(false); - try { - if (decision.action === "wait-for-session") { - await recover(); - } else { - await beginSignIn( - `${location.pathname}${location.search}${location.hash}`, - ); - } - } catch { - setFailed(true); - } finally { - setPending(false); - } - } - if (decision.allowed) return children; if (sessionState === "integration-failed") { return ( -
- -
+ ); } const recovering = decision.action === "wait-for-session"; return ( -
- -
+
); } @@ -402,7 +397,6 @@ function ContextRouteGateway({ buildId, }: Readonly<{ routeModule: ContextRouteModule; buildId: string }>) { const location = useLocation(); - const { message } = useLocale(); const recovery = useApplicationRecovery(); const [routes, setRoutes] = useState(null); const [failure, setFailure] = useState | null>( @@ -451,14 +445,7 @@ function ContextRouteGateway({ ); } - if (routes === null) { - return ( -
-
- ); - } + if (routes === null) return ; const selectedMatch = matchRoutes([...routes], location.pathname)?.at(-1); if (!isContextRouteHandle(selectedMatch?.route.handle)) { diff --git a/src/presentation/templates/page-templates.tsx b/src/presentation/templates/page-templates.tsx index 56f459d1..f9908e9e 100644 --- a/src/presentation/templates/page-templates.tsx +++ b/src/presentation/templates/page-templates.tsx @@ -211,6 +211,10 @@ export function StatusPage( primaryAction?: PageActionDefinition; secondaryAction?: PageActionDefinition; supportReference?: string; + /** Names the answer for tests and telemetry, e.g. `invalid-route`. */ + surface?: string; + /** Extra content under the actions, such as a failure alert. */ + children?: ReactNode; }>, ) { const { message } = useLocale(); @@ -218,6 +222,7 @@ export function StatusPage(
{props.primaryAction || props.secondaryAction ? ( @@ -230,6 +235,7 @@ export function StatusPage( } /> ) : null} + {props.children} {props.supportReference ? (

{message("template.supportReference", { @@ -247,13 +253,15 @@ function PageActionBar(props: Readonly<{ }>) { return (

- {props.actions.map((action) => + {/* Keyed by position: a label that changes while pending must not + remount the button the user just pressed. */} + {props.actions.map((action, index) => action.kind === "link" ? ( {action.label} @@ -261,7 +269,7 @@ function PageActionBar(props: Readonly<{ ) : (