refactor: improve cache handling and logging in CategoryList component to prioritize prerendered cache and enhance data fetching clarity

This commit is contained in:
sebseb7
2025-07-23 10:24:41 +02:00
parent 95f303bc68
commit f3e8395000

View File

@@ -174,20 +174,27 @@ class CategoryList extends Component {
// Ensure cache exists
windowObj.productCache = windowObj.productCache || {};
// Get cache key
const cacheKey = `categoryTree_209_${currentLanguage}`;
// The cache is PRERENDERED - always use it first!
console.log('CategoryList: Checking prerendered cache', windowObj.productCache);
// Use either language-specific or default cache
const cacheKey = `categoryTree_209_${currentLanguage}`;
const defaultCacheKey = "categoryTree_209";
// Try language-specific cache first, then fall back to default
const categoryTree =
windowObj.productCache[cacheKey]?.categoryTree ||
windowObj.productCache[defaultCacheKey]?.categoryTree;
// USE THE CACHE directly - if it has data, use it
const categoryTree = windowObj.productCache[cacheKey]?.categoryTree;
if (categoryTree) {
console.log('CategoryList: Using cached category tree');
console.log('CategoryList: Using prerendered cache');
this.processCategoryTree(categoryTree);
this.setState({ fetchedCategories: true });
return;
}
// No cache, so fetch
console.log('CategoryList: Cache not found, fetching from socket');
// Only fetch if no prerendered cache exists
console.log('CategoryList: No prerendered cache, fetching from socket');
windowObj.productCache[cacheKey] = { fetching: true, timestamp: Date.now() };
this.setState({ fetchedCategories: true });
window.socketManager.emit("categoryList", { categoryId: 209, language: currentLanguage, requestTranslation: true }, (response) => {