Проверка рабочей сборки настоящим браузером (подмена действия на неизвестное серверу и ответ 500) нашла три изъяна: - ответ, набранный в карточке одного вопроса, после самообновления возвращался в поле другого: адресом поля было имя, а на Главной у каждой карточки поле «answer». Адрес теперь — собственный id поля, имя — только когда текстовое поле с таким именем на странице одно; - секрет проекта и ключ сервера вводятся в textarea и попали бы в sessionStorage: поля секретов и кодов по имени не запоминаются; - ошибка, пойманная новой границей app/error.tsx, не уходила в «Ошибки из прода» (на main уходила): Next печатает её console.error, взятым до обёртки ErrorReporter. Граница сама поднимает её через reportError. Тесты на каждый изъян падали до правки; спека, design архива, AGENTS.md и память дополнены. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
34 lines
1.7 KiB
TypeScript
34 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { RefreshCw } from "lucide-react";
|
|
import { useT } from "@/components/I18n";
|
|
import { isStaleAction, reportStaleAction } from "@/components/StaleActionGuard";
|
|
import { reportCaughtError } from "@/lib/stale-action";
|
|
|
|
/**
|
|
* PEP-324: the error boundary of every page. Before it a failed form action (most often a button of a
|
|
* page opened before an update) left the person with Next's «Application error». An unknown action is
|
|
* handed to StaleActionGuard (keep the text, say FORGE was updated, reload); any other error gets a
|
|
* plain screen and is reported to «Ошибки из прода» from here: Next prints a caught error with the
|
|
* console.error it took before ErrorReporter wrapped it, so nobody else would report it.
|
|
*/
|
|
export default function PageError({ error }: { error: Error & { digest?: string } }) {
|
|
const t = useT();
|
|
const stale = isStaleAction(error);
|
|
useEffect(() => {
|
|
if (stale) reportStaleAction();
|
|
else reportCaughtError(error, window);
|
|
}, [stale, error]);
|
|
if (stale) return null;
|
|
return (
|
|
<div role="alert" className="mx-auto flex max-w-lg flex-col items-start gap-3 p-8">
|
|
<p className="text-base font-medium">{t("Страница не открылась из-за ошибки.")}</p>
|
|
<p className="text-sm text-muted-foreground">{t("Обновите страницу или вернитесь назад.")}</p>
|
|
<button type="button" onClick={() => window.location.reload()} className="inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground">
|
|
<RefreshCw className="size-3.5" /> {t("Обновить страницу")}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|