fix: avoid repeated daily starlanguage refresh
Independent Staging Quality Gate / validate (push) Failing after 11m57s
Independent Staging Quality Gate / publish (push) Has been skipped

This commit is contained in:
Jesse_Chen
2026-08-15 23:28:49 +08:00
parent cf945b3455
commit 1084dce770
4 changed files with 88 additions and 2 deletions
+2 -1
View File
@@ -102,6 +102,7 @@ import {
requestOnboardingWithRecovery,
} from "@/lib/onboarding-client";
import { protectOnboardingPhrases } from "@/lib/onboarding-copy";
import { preserveShallowEqual } from "@/lib/preserve-shallow-equal";
import {
SessionModelPersistenceQueue,
persistSessionModelSelection,
@@ -1797,7 +1798,7 @@ export default function Home() {
const latest = await fetchAccount();
if (!accountRefreshGuard.current.isCurrent(requestIdentity)) return;
const nextProfile = readProfile(latest.profile);
setProfile(nextProfile);
setProfile((current) => preserveShallowEqual(current, nextProfile));
setAccount(latest);
setAccountError("");
} catch (caught) {
@@ -0,0 +1,18 @@
export function preserveShallowEqual<T extends object>(current: T, next: T): T {
if (Object.is(current, next)) return current;
const currentRecord = current as Record<string, unknown>;
const nextRecord = next as Record<string, unknown>;
const currentKeys = Object.keys(currentRecord);
const nextKeys = Object.keys(nextRecord);
if (currentKeys.length !== nextKeys.length) return next;
for (const key of currentKeys) {
if (!Object.hasOwn(nextRecord, key) || !Object.is(currentRecord[key], nextRecord[key])) {
return next;
}
}
return current;
}