Fix frontend render bottleneck by caching wishlist (#186)#211
Conversation
|
@devprashant19 is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
BHUVANSH855
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I like the improvements around loading states, stock validation, wishlist synchronization, and category normalization.
However, I have concerns about merging this as-is:
- The PR introduces a very large hardcoded
fallbackProductsdataset, including base64-encoded images and externalgstaticimage URLs. This significantly increases bundle size and makes the code difficult to maintain and review. - Product catalog data should ideally come from backend data or dedicated static assets rather than being embedded directly in
shop.js. - The new hoodie-specific behavior (
showAllHoodies/ "View more Hoodies") introduces category-specific logic that bypasses normal pagination. Could you clarify the product requirement for limiting only hoodies to three items?
Could we move the fallback data out of the main script (or remove it entirely) and document the hoodie behavior before merging?
|
Thanks for the feedback! You are completely right on both points.
|
BHUVANSH855
left a comment
There was a problem hiding this comment.
shop.js introduces a few regressions. fallbackProducts is still referenced but no longer defined, totalPages is not populated from the API response, and there appears to be an extra closing brace in fetchProducts(). Please address these issues before merging.
…Products reference
|
@devprashant19 |
|
Still have conflicts. |
|
@BHUVANSH855 done |
BHUVANSH855
left a comment
There was a problem hiding this comment.
This PR removes the existing fallback product handling and causes the shop/home pages to show empty states whenever the API fails or returns no products. The original implementation provided local fallback data to keep the UI functional.
Additionally, the PR contains corrupted UI text/encoding strings (e.g. Added to cart =���n+�, G�� Prev, Next G��) that need to be corrected before merge.
Please restore the fallback product behavior and fix the broken text/encoding issues.
Fix Performance Bottleneck in Product Rendering
📌 Description
This Pull Request addresses a significant performance bottleneck in the frontend product rendering logic (
frontend/scripts/product-cards-home.js,frontend/scripts/script.js, andfrontend/scripts/shop.js).Previously, the
createProductCardfunction performed synchronouslocalStoragereads on every invocation by callingAppUtils.getWishlist()to check if a product was in the user's wishlist. Because this was executed inside a loop for every product being rendered, it caused redundant I/O operations and layout thrashing.This PR optimizes the rendering pipeline by computing the user's wishlist IDs once (as a
Set) prior to the rendering loop, and passing theSetdown into thecreateProductCardfunction.Closes #186
🔄 Changes Made
createProductCardSignature: Modified the function across the frontend scripts to optionally accept a pre-computedwishlistIdsSet.renderFeaturedProducts,renderNewArrivals, and generalrenderProductsfunctions to fetchAppUtils.getWishlist()once before iteration and map it into a fast-lookupSet.AppUtils.getWishlist().some(...)within the component template with aO(1)Set.has(...)check when the IDs are provided.🧪 How to Test
localStorage.getItemis now only called once prior to product rendering instead of repeatedly.✅ Checklist
localStoragereads.