fix: seed home categories from cache to stop icon flicker
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 29s
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 29s
Initialize the categories state from the cached response on first render so the category icons stay visible when navigating back to the home page, instead of flashing empty for a frame. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,7 +45,15 @@ export function Home() {
|
||||
const { t, lang } = useI18n();
|
||||
const lp = useLocalizedPath();
|
||||
const { hash } = useLocation();
|
||||
const [cats, setCats] = useState<Category[]>([]);
|
||||
// Seed from cache on the first render so the categories (and their icons)
|
||||
// are present immediately when navigating back to the home page, instead of
|
||||
// flashing empty for a frame before the effect re-applies the cached data.
|
||||
const [cats, setCats] = useState<Category[]>(() => {
|
||||
const cached = readJSONCache<Category[]>(
|
||||
`/api/categories?lang=${encodeURIComponent(langQuery(lang))}`,
|
||||
);
|
||||
return cached ? itemsOrEmpty(cached) : [];
|
||||
});
|
||||
const [rec, setRec] = useState<PostBackedResource[]>([]);
|
||||
const [latestPosts, setLatestPosts] = useState<Post[]>([]);
|
||||
const [popular, setPopular] = useState<PostBackedResource[]>([]);
|
||||
|
||||
Reference in New Issue
Block a user