fix: harden mobile rectification recovery

fix: harden mobile rectification recovery
This commit is contained in:
732642856
2026-07-20 16:03:50 +08:00
committed by GitHub
5 changed files with 36 additions and 1 deletions
+1
View File
@@ -208,6 +208,7 @@ button:disabled { cursor: default; opacity: .45; }
}
@media (max-width: 767px) {
.conversation.is-empty { display: block; }
.brand-row { padding: 0 4px; }
.brand-mark { width: 26px; height: 26px; }
.session-nav { overflow: hidden; }
@@ -20,6 +20,7 @@ import {
saveGuidedBirthTimeCandidate,
} from "@/lib/birth-time-guided-client";
import { confirmReviewedBirthTimeDraft } from "@/lib/birth-time-guided-draft-confirmation";
import { birthTimeUserError } from "@/lib/birth-time-user-error";
import {
claimMutation,
createStableActionIdentityRegistry,
@@ -198,7 +199,7 @@ export function useBirthTimeGuidedJourney(input: GuidedJourneyInput): BirthTimeG
: completeGuidedBirthTimeCandidate({ caseId: turn.caseId, resultId, time });
void completion
.then(() => onCandidateComplete(turn, time))
.catch((caught) => setError(caught instanceof Error ? caught.message : "候选时间暂时无法保存"))
.catch((caught) => setError(birthTimeUserError(caught)))
.finally(() => {
release();
setPending(false);
@@ -0,0 +1,9 @@
const unsafeImplementationMessage = /expected pattern|failed to fetch|networkerror|load failed|domexception|syntaxerror/i;
export function birthTimeUserError(error: unknown): string {
const message = error instanceof Error ? error.message.trim() : "";
if (!message || unsafeImplementationMessage.test(message) || !/[\u3400-\u9fff]/u.test(message)) {
return "候选时间暂时无法保存,请检查网络后重试。";
}
return message;
}
@@ -0,0 +1,10 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
test("mobile rectification welcome content starts at the scroll origin", () => {
assert.match(css, /@media \(max-width: 767px\)[\s\S]*?\.conversation\.is-empty\s*\{[^}]*display:\s*block/);
assert.match(css, /\.conversation\s*\{[^}]*min-height:\s*0[^}]*overflow-y:\s*auto/);
});
@@ -0,0 +1,14 @@
import assert from "node:assert/strict";
import test from "node:test";
import { birthTimeUserError } from "../src/lib/birth-time-user-error.ts";
test("birth-time errors never expose browser implementation messages", () => {
assert.equal(
birthTimeUserError(new DOMException("The string did not match the expected pattern.")),
"候选时间暂时无法保存,请检查网络后重试。",
);
});
test("birth-time errors preserve a safe server message", () => {
assert.equal(birthTimeUserError(new Error("候选结果已变化")), "候选结果已变化");
});