mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
Merge branch 'fix/374-share-render' into release/v1.25.0
This commit is contained in:
commit
32885d1218
13 files changed
+158
-36
No files matched your search
@@ -72,6 +72,15 @@ function isGate(out: unknown): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the props the page handed to the gate element. A client component
|
||||
* boundary can only carry serializable props — issue #374 was a `t` FUNCTION
|
||||
* crossing it, which throws at render.
|
||||
*/
|
||||
function gateProps(out: unknown): Record<string, unknown> {
|
||||
return (out as { props: Record<string, unknown> }).props;
|
||||
}
|
||||
|
||||
function resolvedContext() {
|
||||
return {
|
||||
shareLinkId: "link-1",
|
||||
@@ -126,6 +135,23 @@ describe("clinician share page", () => {
|
||||
expect(isGate(out)).toBe(true);
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(loadData).not.toHaveBeenCalled();
|
||||
|
||||
// Issue #374 contract: every prop crossing the server→client boundary must
|
||||
// be serializable. NO prop value may be a function (a `t` function here
|
||||
// throws "Server Components render error"), and the copy must arrive as a
|
||||
// pre-resolved plain object.
|
||||
const props = gateProps(out);
|
||||
for (const value of Object.values(props)) {
|
||||
expect(typeof value).not.toBe("function");
|
||||
}
|
||||
expect(typeof props.token).toBe("string");
|
||||
const strings = props.strings as Record<string, unknown>;
|
||||
expect(strings).toBeTypeOf("object");
|
||||
expect(strings).not.toBeNull();
|
||||
expect(Object.values(strings).length).toBeGreaterThan(0);
|
||||
for (const value of Object.values(strings)) {
|
||||
expect(typeof value).toBe("string");
|
||||
}
|
||||
});
|
||||
|
||||
it("renders a protected link WITH a valid unlock cookie", async () => {
|
||||
|
||||
@@ -82,7 +82,17 @@ export default async function ClinicianSharePage({
|
||||
if (!verifyUnlockValue(unlockValue, gate.tokenHash)) {
|
||||
const locale = await resolveLocale();
|
||||
const { t } = getServerTranslator(locale);
|
||||
return <ShareUnlockGate t={(key, vars) => t(key, vars)} token={token} />;
|
||||
// Resolve the gate copy on the server (it owns the locale) into a plain,
|
||||
// serializable object. A `t` function cannot cross the RSC boundary into
|
||||
// the client gate — passing one throws at render (issue #374).
|
||||
const strings = {
|
||||
title: t("clinicianView.unlock.title"),
|
||||
description: t("clinicianView.unlock.description"),
|
||||
label: t("clinicianView.unlock.label"),
|
||||
error: t("clinicianView.unlock.error"),
|
||||
submit: t("clinicianView.unlock.submit"),
|
||||
};
|
||||
return <ShareUnlockGate strings={strings} token={token} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Error boundary for the public clinician share route (`/c/<token>`).
|
||||
*
|
||||
* The share view carries no app chrome and no session, so a render failure must
|
||||
* not fall through to the full-app error screen. This renders a clean, locale-
|
||||
* aware, stack-free message and offers a single retry. No record data, no
|
||||
* digest, no stack — a probe learns nothing from a failed render.
|
||||
*/
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function ClinicianShareError({
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string };
|
||||
reset: () => void;
|
||||
}) {
|
||||
const { t } = useTranslations();
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex min-h-screen max-w-md flex-col justify-center px-4">
|
||||
<div className="border-border bg-card space-y-4 rounded-lg border p-6 text-center">
|
||||
<h1 className="text-lg font-semibold">
|
||||
{t("clinicianView.loadError.title")}
|
||||
</h1>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("clinicianView.loadError.description")}
|
||||
</p>
|
||||
<Button
|
||||
onClick={() => reset()}
|
||||
className="min-h-11 w-full sm:min-h-9"
|
||||
variant="outline"
|
||||
>
|
||||
{t("clinicianView.loadError.retry")}
|
||||
</Button>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user