fix: 修复路由初始化竞态、存储状态静默覆盖与存储清理误删

This commit is contained in:
Cursor Agent
2026-06-26 09:12:58 +00:00
committed by 雨霖铃
parent 1948ba67a7
commit 0545910b16
7 changed files with 137 additions and 11 deletions
@@ -166,4 +166,18 @@ describe('useStorageState', () => {
expect(result.current[2]).toBe(false);
});
it('加载失败时不应把快照默认值写回 Chrome Storage', async () => {
localStorage.setItem('snapshot/app/searchHistory', JSON.stringify([]));
(storageUtil.get as any).mockRejectedValue(new Error('Storage read failed'));
renderHook(() =>
useStorageState('app/searchHistory', [], (val): val is string[] => Array.isArray(val)),
);
await waitFor(() => {
expect(storageUtil.set).not.toHaveBeenCalled();
});
});
});