From abf94eba862303c365912eeeed377157d0d5b5a1 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Wed, 23 Jul 2025 09:54:58 +0200 Subject: [PATCH] refactor: add detailed logging for productCache checks in Content component to aid in debugging category data fetching --- src/components/Content.js | 42 +++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/components/Content.js b/src/components/Content.js index c785d14..f068a63 100644 --- a/src/components/Content.js +++ b/src/components/Content.js @@ -202,6 +202,16 @@ class Content extends Component { } componentDidMount() { + // Debug check for window.productCache + console.log("Content componentDidMount - window.productCache exists:", !!window.productCache); + if (window.productCache) { + console.log("Content componentDidMount - window.productCache keys:", Object.keys(window.productCache)); + if (window.productCache["categoryTree_209"]) { + console.log("Content componentDidMount - categoryTree_209.categoryTree exists:", + !!window.productCache["categoryTree_209"].categoryTree); + } + } + if(this.props.params.categoryId) {this.setState({loaded: false, unfilteredProducts: [], filteredProducts: [], attributes: [], categoryName: null, childCategories: []}, () => { this.fetchCategoryData(this.props.params.categoryId); })} @@ -259,15 +269,29 @@ class Content extends Component { fetchCategoryData(categoryId) { - // Direct check for the specific cache key mentioned in the requirement - const hasCategoryTree = window.productCache && window.productCache["categoryTree_209"]; + console.log("Checking for category tree in cache"); + console.log("window.productCache exists:", !!window.productCache); + if (window.productCache) { + console.log("window.productCache keys:", Object.keys(window.productCache)); + console.log("categoryTree_209 exists:", !!window.productCache["categoryTree_209"]); + if (window.productCache["categoryTree_209"]) { + console.log("categoryTree exists:", !!window.productCache["categoryTree_209"].categoryTree); + } + } - // Check for specific category data in cache - const cachedData = getCachedCategoryData(categoryId); - - // If we have the category tree data, use it and don't query socket.io - if (hasCategoryTree) { - console.log("Found categoryTree_209 in cache"); + // IMPORTANT: Check for the exact structure mentioned in the requirement + // window.productCache = {"categoryTree_209":{"categoryTree": ...}} + if (typeof window.productCache === 'object' && + window.productCache !== null && + typeof window.productCache["categoryTree_209"] === 'object' && + window.productCache["categoryTree_209"] !== null && + typeof window.productCache["categoryTree_209"].categoryTree === 'object' && + window.productCache["categoryTree_209"].categoryTree !== null) { + + console.log("Found categoryTree_209.categoryTree in cache"); + + // Check for specific category data in cache + const cachedData = getCachedCategoryData(categoryId); if (cachedData) { console.log("Using cached category data for", categoryId); @@ -286,6 +310,8 @@ class Content extends Component { return; } } + + console.log("No category tree found in cache, proceeding with socket.io query"); // Only if we don't have the category tree in cache, proceed with socket.io query console.log(`productList:${categoryId}`);