Rendering Weaverse Pages
This guide covers everything you need to know about rendering different page types in Weaverse, from basic concepts to advanced implementation patterns.Core Concepts
Weaverse page rendering revolves around two key elements:loadPage()
function: Loads page data based on type and handleWeaverseContent
component: Renders the loaded page content
The loadPage() Function
TheloadPage()
function is called in your route loaders to fetch page data:
The WeaverseContent Component
TheWeaverseContent
component renders the loaded page data. It automatically gets the weaverseData
from your loader through the <WeaverseHydrogenRoot>
wrapper:
<WeaverseHydrogenRoot>
component (typically in your root layout) automatically extracts weaverseData
from the current route’s loader data and provides it to all child <WeaverseContent>
components through React context. This eliminates the need to manually pass the data prop.
Supported Page Types
Weaverse supports the following page types:E-commerce Pages
PRODUCT
- Individual product pagesCOLLECTION
- Collection/category listing pages
Content Pages
PAGE
- Custom pages created in Weaverse StudioBLOG
- Blog listing pagesARTICLE
- Individual blog post pages
Special Pages
INDEX
- HomepageCUSTOM
- Custom pages created in Weaverse Studio (no specific handle needed)
Routes Without Weaverse Integration
Some routes in your Hydrogen theme may not use Weaverse’s page system at all. These typically include functional pages that rely heavily on Shopify’s built-in components and APIs:- Search pages - Use Shopify’s search API directly
- Cart pages - Use Shopify’s cart components and forms
- Account pages - Use Shopify’s customer account API
- Policy pages - Often render Shopify’s policy content directly
Custom Page Approach
Weaverse provides two ways to create custom pages:Option 1: PAGE Type with Handle
For specific custom pages with defined handles:Option 2: CUSTOM Type for Dynamic Routing
For catch-all routing where URL determines the page content:Real-World Example: Pilot Template Pattern
The official Pilot template demonstrates this mixed approach. Here are examples from actual implementation:- Homepage route (
_index.tsx
) detects when a URL parameter isn’t a locale and switches to"CUSTOM"
type - Catch-all route (
$.tsx
) handles any remaining unmatched routes as custom Weaverse pages - Both routes use
validateWeaverseData()
to ensure the page exists before rendering
Basic Implementation
Here’s the standard pattern for implementing Weaverse page rendering in a React Router v7 route:1. Route Loader
2. Route Component
Page Type Examples
Product Page
Collection Page
Custom Page
Blog Page
Homepage
Custom Pages
Custom pages are created in Weaverse Studio and can be rendered using thePAGE
type:
Creating Custom Routes
For user-friendly URLs, create custom routes that map to Weaverse pages:Dynamic Custom Pages
Create a catch-all route for dynamic custom pages:Error Handling
404 Error Handling
Always check if the page data exists and handle 404 cases:Fallback Rendering
Provide fallback content when Weaverse data is unavailable:Error Boundaries
Use error boundaries for graceful error handling:Performance Best Practices
Parallel Data Loading
Always load Weaverse data in parallel with other API calls:Caching
Use proper cache headers for Weaverse pages:Preloading
Consider preloading critical page data:Troubleshooting
Common Issues
1. Page Type Mismatch
Problem: Wrong page type specified inloadPage()
2. Missing Handle Parameter
Problem: Handle not provided or undefined3. Component Not Rendering
Problem: Weaverse components not registered properly Solution: Ensure components are registered in~/weaverse/components.ts
(or ~/app/weaverse/components.ts
in Pilot template):
* as ComponentName
) and restart your dev server after registration.
4. TypeScript Errors
Problem: Type errors withWeaverseContent
Solution: Ensure proper type imports:
Debug Mode
Enable debug mode to troubleshoot page loading issues:Next Steps
- Learn about Custom Component Development
- Explore Data Fetching Patterns
- Master Component Schemas
- Review API Reference