fix(web): сводка, догруженная при уходе с ОСВ, не кешируется (M-9)
Сводка живёт только в состоянии ожидающего перехода; при summary=null запрашивается заново. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2bb5683cde
commit
7c523b93d1
@ -70,7 +70,8 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { tab } = useParams<{ tab?: string }>();
|
const { tab } = useParams<{ tab?: string }>();
|
||||||
const [pending, setPending] = useState<string | null>(null);
|
// переход, ожидающий решения в модалке; сводка — та, по которой модалка показана (только на время модалки)
|
||||||
|
const [pending, setPending] = useState<{ key: string; summary: OsvSummaryOut | null } | null>(null);
|
||||||
|
|
||||||
const activeKey = tab || 'osv';
|
const activeKey = tab || 'osv';
|
||||||
|
|
||||||
@ -79,12 +80,7 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
navigate(to, options);
|
navigate(to, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
// сводка, догруженная при уходе, пока страница её не передала (или запрос страницы упал); привязана к версии
|
|
||||||
const [fetched, setFetched] = useState<{ versionId: string; summary: OsvSummaryOut } | null>(null);
|
|
||||||
const [checking, setChecking] = useState(false);
|
const [checking, setChecking] = useState(false);
|
||||||
const fetchedSummary = fetched?.versionId === versionId ? fetched.summary : null;
|
|
||||||
const known = summary ?? fetchedSummary;
|
|
||||||
const shownPairs = known?.counter_pairs ?? [];
|
|
||||||
|
|
||||||
// актуальные версия и признак «компонент жив» — ответ запроса, пришедший после смены версии/размонтирования, игнорируется
|
// актуальные версия и признак «компонент жив» — ответ запроса, пришедший после смены версии/размонтирования, игнорируется
|
||||||
const liveRef = useRef({ versionId, mounted: true });
|
const liveRef = useRef({ versionId, mounted: true });
|
||||||
@ -104,7 +100,7 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const storage = safeSessionStorage();
|
const storage = safeSessionStorage();
|
||||||
let found: OsvSummaryOut | null = known;
|
let found: OsvSummaryOut | null = summary;
|
||||||
let decision: 'warn' | 'go' | 'perform' = decideOsvLeave({ summary: found, versionId, status, storage });
|
let decision: 'warn' | 'go' | 'perform' = decideOsvLeave({ summary: found, versionId, status, storage });
|
||||||
if (decision === 'perform') {
|
if (decision === 'perform') {
|
||||||
setChecking(true);
|
setChecking(true);
|
||||||
@ -118,13 +114,12 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
if (!liveRef.current.mounted) return;
|
if (!liveRef.current.mounted) return;
|
||||||
setChecking(false);
|
setChecking(false);
|
||||||
if (liveRef.current.versionId !== requestedFor) return;
|
if (liveRef.current.versionId !== requestedFor) return;
|
||||||
if (result) setFetched({ versionId: requestedFor, summary: result });
|
|
||||||
found = result;
|
found = result;
|
||||||
decision = resolveLeaveAfterFetch({ summary: result, versionId, status, storage });
|
decision = resolveLeaveAfterFetch({ summary: result, versionId, status, storage });
|
||||||
}
|
}
|
||||||
if (decision === 'warn' && found) {
|
if (decision === 'warn' && found) {
|
||||||
rememberCounterPairsShown(versionId, found.counter_pairs, storage);
|
rememberCounterPairsShown(versionId, found.counter_pairs, storage);
|
||||||
setPending(newKey);
|
setPending({ key: newKey, summary: found });
|
||||||
} else {
|
} else {
|
||||||
go(newKey);
|
go(newKey);
|
||||||
}
|
}
|
||||||
@ -162,8 +157,8 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
/>
|
/>
|
||||||
<CounterPairsModal
|
<CounterPairsModal
|
||||||
open={pending !== null}
|
open={pending !== null}
|
||||||
pairs={shownPairs}
|
pairs={pending?.summary?.counter_pairs ?? []}
|
||||||
unmappedTotal={known?.unmapped_total ?? 0}
|
unmappedTotal={pending?.summary?.unmapped_total ?? 0}
|
||||||
onShow={() => {
|
onShow={() => {
|
||||||
setPending(null);
|
setPending(null);
|
||||||
navigate(
|
navigate(
|
||||||
@ -173,7 +168,7 @@ export function OsvTabs({ summary, versionId, status }: Props) {
|
|||||||
}}
|
}}
|
||||||
onStay={() => setPending(null)}
|
onStay={() => setPending(null)}
|
||||||
onGo={() => {
|
onGo={() => {
|
||||||
const next = pending;
|
const next = pending?.key;
|
||||||
setPending(null);
|
setPending(null);
|
||||||
if (next) go(next);
|
if (next) go(next);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user