WeaverseClient
TheWeaverseClient class is a server-side utility that provides methods to interact with Weaverse services, fetch content, manage caching strategies, and load theme settings and page data for your Hydrogen storefront.
Initialization
TheWeaverseClient is typically initialized in your server.ts file and injected into your app’s load context:
Type Definition
Methods
fetchWithCache
Fetches data from an external API with configurable caching strategies.url: string- The endpoint URLoptions?: RequestInit & { strategy?: AllCacheOptions }- Cache and fetch configurationstrategy- Caching strategy with options likemaxAge,staleWhileRevalidate, etc.- Other standard
fetchoptions (headers,method, etc.)
Promise<T>- A promise that resolves with the fetched data
loadThemeSettings
Loads the global theme settings for the current Weaverse project.strategy?: AllCacheOptions- Optional caching strategy for the theme settings request
Promise<HydrogenThemeSettings>- The theme settings object
loadPage
Loads a page’s data from Weaverse, including running component loaders and handling localization.type?: PageType
type?: PageType
Page type identifier determining the kind of content to load.Supported types:
'INDEX'- Homepage'PRODUCT'- Product detail pages'COLLECTION'- Collection/category pages'PAGE'- Custom pages created in Weaverse Studio'BLOG'- Blog listing pages'ARTICLE'- Individual blog post pages'CUSTOM'- Dynamic custom pages
locale?: string
locale?: string
Locale identifier for loading localized content.Format:
language-country (lowercase, hyphen-separated)- Language: ISO 639-1 code (2 letters, e.g.,
sv,en,fr) - Country: ISO 3166-1 alpha-2 code (2 letters, e.g.,
se,us,ca)
"en-us"- English in United States"sv-se"- Swedish (sv) in Sweden (se)"fr-ca"- French (fr) in Canada (ca)"de-de"- German (de) in Germany (de)
- Path prefix from URL (deprecated)
- Auto-detection from
context.storefront.i18n.pathPrefix
en-us (smart fallback coming in future release).When to use explicit locale:- Custom routing logic determines locale
- Loading content for different locale than current page
- Background jobs without request context
- Cross-locale content comparison
handle?: string
handle?: string
Page handle/slug identifier for specific content.Required for:
PRODUCT- Product handle (e.g.,"classic-varsity-jacket")COLLECTION- Collection handle (e.g.,"summer-collection")PAGE- Custom page handle from StudioBLOG- Blog handleARTICLE- Article handle
INDEX- Homepage (no handle needed)CUSTOM- Dynamic custom pages (URL determines content)
projectId?: string
projectId?: string
Weaverse project ID for multi-project architectures.Default: Value from Important: Set up
WEAVERSE_PROJECT_ID environment variableWhen to use:- Multi-brand storefronts sharing infrastructure
- Different projects per market or locale
- A/B testing different project configurations
- Staging vs production project separation
projectId in WeaverseClient initialization for automatic domain-based routing. Route-level override is available for special cases.See Multi-Project Architecture Guide for comprehensive implementation details, including A/B testing, multi-brand setups, and step-by-step migration guides.strategy?: AllCacheOptions
strategy?: AllCacheOptions
Caching strategy configuration for the page data request.Options:
mode?- Cache control mode:'public','private','no-cache','no-store','must-revalidate'maxAge?- Cache duration in secondsstaleWhileRevalidate?- Serve stale content while revalidating in secondssMaxAge?- Shared cache (CDN) duration in secondsstaleIfError?- Serve stale content if error occurs in seconds
Promise<WeaverseLoaderData | null>- Page data object ornullif not found
- Rendering Weaverse Pages - Complete guide to page rendering
- Advanced Localization - Locale detection and multi-project setup
- Multi-Project Architecture - A/B testing, multi-brand, and advanced routing
- Markets & Localization - Studio workflow for localized content
execComponentLoader
Executes a component’s loader function to fetch its data.item: HydrogenComponentData- Component data object
Promise<HydrogenComponentData>- Component data with loader data added
loadPage to process component loaders.
generateFallbackPage
Generates a fallback page when the requested page data isn’t available.message: string- Message to display on the fallback page
HydrogenPageData- A basic page data object with the message
Related
- useWeaverse - Hook for accessing Weaverse instance client-side
- Data Fetching and Caching - Advanced guide on data fetching