diff --git a/prerender.cjs b/prerender.cjs index 72e21d2..4761e51 100644 --- a/prerender.cjs +++ b/prerender.cjs @@ -202,7 +202,8 @@ const renderProductWorker = async (productSeoNames, workerId, progressCallback, combinedMetaTags, true, config, - true // Suppress logs during parallel rendering to avoid interfering with progress bar + true, // Suppress logs during parallel rendering to avoid interfering with progress bar + productDetails // Pass product data for cache population ); if (success) { diff --git a/prerender/renderer.cjs b/prerender/renderer.cjs index f5640d4..d5a9c67 100644 --- a/prerender/renderer.cjs +++ b/prerender/renderer.cjs @@ -17,7 +17,8 @@ const renderPage = ( metaTags = "", needsRouter = false, config, - suppressLogs = false + suppressLogs = false, + productData = null ) => { const { isProduction, @@ -203,6 +204,21 @@ const renderPage = ( `; } + // Create script to populate window.productDetailCache for individual product pages + let productDetailCacheScript = ''; + if (productData && productData.product) { + const productDetailCacheData = JSON.stringify(productData.product); + productDetailCacheScript = ` + + `; + } + // Combine all CSS (global + inlined) into a single optimized style tag const combinedCss = globalCss + (inlinedCss ? '\n' + inlinedCss : ''); const combinedCssTag = combinedCss ? `` : ''; @@ -214,7 +230,7 @@ const renderPage = ( template = template.replace( "", - `${resourceHints}${combinedCssTag}${additionalTags}${metaTags}${prerenderFallbackScript}${productCacheScript}` + `${resourceHints}${combinedCssTag}${additionalTags}${metaTags}${prerenderFallbackScript}${productCacheScript}${productDetailCacheScript}` ); const rootDivRegex = /
[\s\S]*?<\/div>/; @@ -244,6 +260,9 @@ const renderPage = ( console.log(` - Total inlined CSS: ${Math.round(combinedCss.length / 1024)}KB`); console.log(` - Render-blocking CSS eliminated: ${inlinedCss ? 'YES' : 'NO'}`); console.log(` - Fallback content saved to window.__PRERENDER_FALLBACK__`); + if (productDetailCacheScript) { + console.log(` - Product detail cache populated for SPA hydration`); + } } return true; diff --git a/src/components/ProductDetailPage.js b/src/components/ProductDetailPage.js index 1b7addd..4ce2fee 100644 --- a/src/components/ProductDetailPage.js +++ b/src/components/ProductDetailPage.js @@ -585,6 +585,7 @@ class ProductDetailPage extends Component { pb: { xs: 4, md: 8 }, maxWidth: "1400px", mx: "auto", + flexGrow: 1 }} > {/* Breadcrumbs */}