PEP-141: the dev «Issue» pill and overlay are hidden from users; console errors of the browser go to Bugsink
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
45c9d0eddd
commit
66fefa6664
@ -113,3 +113,9 @@
|
||||
@keyframes pug-zzz { 0%, 100% { opacity: 0.25; transform: translateY(2px); } 50% { opacity: 0.6; transform: translateY(-2px); } }
|
||||
@keyframes pug-tilt { 0%, 60%, 100% { transform: rotate(0deg); } 70% { transform: rotate(-7deg); } 85% { transform: rotate(4deg); } }
|
||||
@keyframes pug-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
|
||||
|
||||
/* PEP-137: the live site runs `next dev` before launch; its «N Issue» pill and error overlay are
|
||||
developer tools — a product person must never see them. Errors go to Bugsink (ErrorReporter). */
|
||||
nextjs-portal {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@ -4,6 +4,33 @@ import { useEffect } from "react";
|
||||
|
||||
const MAX_PER_PAGE = 10;
|
||||
|
||||
// PEP-137: what the page writes to console.error (a hydration mismatch, a React warning that the
|
||||
// dev overlay shows as «1 Issue») never reaches window.onerror. The wrapper is installed when
|
||||
// this module loads — before hydration — and keeps the first messages until the reporter mounts.
|
||||
const consoleErrors: Array<{ message: string; stack?: string }> = [];
|
||||
let onConsoleError: ((e: { message: string; stack?: string }) => void) | null = null;
|
||||
if (typeof window !== "undefined" && !(window as { __peppaConsoleWrapped?: boolean }).__peppaConsoleWrapped) {
|
||||
(window as { __peppaConsoleWrapped?: boolean }).__peppaConsoleWrapped = true;
|
||||
const original = console.error.bind(console);
|
||||
console.error = (...args: unknown[]) => {
|
||||
original(...args);
|
||||
try {
|
||||
const err = args.find((a): a is Error => a instanceof Error);
|
||||
const message = args
|
||||
.map((a) => (a instanceof Error ? a.message : typeof a === "string" ? a : JSON.stringify(a) ?? ""))
|
||||
.join(" ")
|
||||
.replace(/%[sdoc]/g, "")
|
||||
.trim();
|
||||
if (!message) return;
|
||||
const entry = { message, stack: err?.stack };
|
||||
if (onConsoleError) onConsoleError(entry);
|
||||
else if (consoleErrors.length < MAX_PER_PAGE) consoleErrors.push(entry);
|
||||
} catch {
|
||||
/* reporting must never break the page */
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** PEP-91: browser errors of Peppa's own pages → /api/client-errors → Bugsink (PEP-web). */
|
||||
export function ErrorReporter() {
|
||||
useEffect(() => {
|
||||
@ -28,9 +55,12 @@ export function ErrorReporter() {
|
||||
if (r instanceof Error) send(r.name, r.message, r.stack);
|
||||
else send("UnhandledRejection", typeof r === "string" ? r : JSON.stringify(r) ?? "");
|
||||
};
|
||||
onConsoleError = (e) => send("ConsoleError", e.message, e.stack);
|
||||
for (const e of consoleErrors.splice(0)) onConsoleError(e);
|
||||
window.addEventListener("error", onError);
|
||||
window.addEventListener("unhandledrejection", onRejection);
|
||||
return () => {
|
||||
onConsoleError = null;
|
||||
window.removeEventListener("error", onError);
|
||||
window.removeEventListener("unhandledrejection", onRejection);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user