← Back to blog
by rn00m

Headless Shopify Project


1. Data & API Layer Layer (src/lib/shopify/api.ts)

  • Fixed Query Collisions: Fixed validation errors where your shared collection queries were crashing because of duplicate field requests and unsupported totalCount parameters in the Storefront API [21].
  • Added Safe Type Casting: Hardcoded checks into getCollectionByHandle to safely fall back to ‘BEST_SELLING’ styles if a system collection like ‘all’ accidentally calls COLLECTION_DEFAULT, stopping silent data drops.
  • Enforced Mandatory Variables: Ensured functions passing parameters mapped to required GraphQL types (like Int!) fall back to structural integer defaults rather than passing undefined parameters.

2. Collection Abstraction Mapping Layer (src/lib/products.ts)

  • Fixed the Mock Trap: Rewrote the collection routers to guarantee they cleanly process live production connections when PUBLIC_USE_MOCK_PRODUCTS=false is activated.
  • Synchronized Object Schemas: Ensured that the backend production pipeline safely forwards request variables directly into your custom shopify/api.ts file without breaking internal component references.

3. Layout Architecture & Componentization (src/pages/index.astro)

  • Componentized Layout Sections: Split up monolithic home layout scripts into dedicated, self-contained Astro modules (FeaturedGrid.astro and CollectionList.astro) for easy structural reuse across the store.
  • Cleaned Viewport Constraints: Shifted the Hero view away from a congested full-screen layout to a natural viewport flow, allowing the bento product items to overlap beautifully using negative top margin styles (-mt-12).
  • Added Server Performance Optimizations: Configured advanced multi-minute Edge CDN server cache parameters (Cache-Control header) right into your homepage frontmatter for near-instant response times.

4. Component Refactoring & Visual Fallbacks (src/components/)

  • Added Image Fallback UI: Upgraded collection card loops to check for missing graphics, swapping an empty container background for a highly stylized CSS slate gradient block whenever image values return null.
  • Responsive Shopify Image CDN Trimming: Enhanced ProductCard.astro to sniff out layout flags (variant === ‘minimal’). It appends smart dynamic format resizing handles (width=500&format=webp) to Shopify’s network image strings to reduce page weight for mobile users.
  • Optimized Image Layout Shifts: Added hardcoded mathematical height parameters calculated directly from your container’s 4/5 layout properties to eliminate visual layout jumps during content rendering.

What’s Next on the Roadmap?

  • Setting up the ⌘K Search Modal interaction scripting.Completed
  • Filtering out duplicate items from appearing in both your Bento Grid and the Discover Carousel.Completed
  • ~~Fixing the cart marker bug. ✅ Completed