> ## Documentation Index
> Fetch the complete documentation index at: https://weaverse.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Weaverse component configuration uses `settings`. `inspector` is deprecated; never generate it.
> Weaverse Hydrogen themes use React Router v7: import from `react-router`, never `react-router-dom` or `@remix-run/*`.
> Before using any code sample, read `@weaverse/hydrogen` in the project's `package.json`: 6.x and 5.x import from different entries and use different type names, so code for one does not build on the other.
> `@weaverse/hydrogen` 6 (Shopify Hydrogen 2026.10 and later, the version these docs show) imports from `@weaverse/hydrogen/react-router` and uses `Weaverse*` types such as `WeaverseComponentProps`, `WeaverseComponentLoaderArgs` and `WeaverseComponentSchema`; the root `@weaverse/hydrogen` entry only exports `createSchema()`, data helpers and types.
> `@weaverse/hydrogen` 5.x (Hydrogen 2026.4 and earlier) imports everything from `@weaverse/hydrogen` and uses `HydrogenComponentProps`, `ComponentLoaderArgs` and `HydrogenComponentSchema`. On a 5.x project, convert samples to these names. Upgrade to 6 only when asked (`npx @weaverse/cli@latest migrate v6`, plus the Hydrogen 2026.10 upgrade). Do not mix major versions.
> Next.js themes use `@weaverse/hydrogen` 6.2.0 or later: import client and shared code from `@weaverse/hydrogen/next` and server-only code from `@weaverse/hydrogen/next/server`. `@weaverse/next` is deprecated; never install or import it.
> For live project data (pages, theme settings, translations), use the Weaverse MCP server: https://weaverse.io/docs/developer-tools/weaverse-mcp

# WeaverseClient

> Server-side client for loading Weaverse content in Shopify Hydrogen.

# WeaverseClient

`WeaverseClient` loads Weaverse page data, theme settings, and custom page metadata on the server. It also runs registered component loaders and integrates with Hydrogen caching.

## Initialization

Create the client once per request in your app context, from the request's Hydrogen 2026.10 Storefront API client. Pilot does this in `app/.server/context.ts`:

```tsx theme={null}
import { WeaverseClient } from '@weaverse/hydrogen/react-router'

export async function createAppContext(
  request: Request,
  env: Env,
  executionContext: ExecutionContext
) {
  const waitUntil = executionContext.waitUntil.bind(executionContext)
  const [cache, session] = await Promise.all([
    caches.open('hydrogen'),
    AppSession.init(request, [env.SESSION_SECRET]),
  ])
  const storefront = createRequestStorefront({ request, env, cache, waitUntil })
  const customerAccount = createCustomerAccount({ env, request, session, storefront })

  const weaverse = new WeaverseClient({
    storefront,
    env,
    cache,
    waitUntil,
    request,
    customerAccount, // Optional: passed through to section loaders
    themeSchema,
    components,
    // Optional: the market's public locale, when it differs from `storefront.i18n`
    locale: resolveRequestLocale(request),
    // Optional: override env-based project resolution
    projectId: env.WEAVERSE_PROJECT_ID,
    // Optional: request timeout in milliseconds
    fetchTimeoutMs: 10_000,
  })

  return { env, cache, waitUntil, session, storefront, customerAccount, weaverse }
}
```

`createRequestStorefront`, `createCustomerAccount`, `AppSession` and `resolveRequestLocale` are app code; see [Step 4 of the v6 migration guide](https://weaverse.io/docs/migration-advanced/v6-migration.md#step-4-build-the-app-context-yourself). `server.ts` copies the returned object onto React Router's context, so loaders read `context.weaverse`.

See the [Project Structure guide](https://weaverse.io/docs/core-concepts/project-structure.md#base-files-explained) for the complete setup.

## Public API

```typescript theme={null}
class WeaverseClient {
  constructor(args: WeaverseClientArgs)

  API: 'v1'
  basePageConfigs: Omit<WeaverseProjectConfigs, 'requestInfo'>
  basePageRequestBody: Omit<FetchProjectRequestBody, 'url'>
  configs: WeaverseProjectConfigs
  storefront: WeaverseClientArgs['storefront']
  customerAccount: WeaverseClientArgs['customerAccount']
  env: WeaverseClientArgs['env']
  cache: WeaverseClientArgs['cache']
  waitUntil: WeaverseClientArgs['waitUntil']
  request: WeaverseClientArgs['request']
  components: WeaverseClientArgs['components']
  themeSchema: WeaverseClientArgs['themeSchema']

  fetchWithCache<T>(
    url: string,
    options?: WeaverseFetchWithCacheOptions
  ): Promise<T>
  fetchCustomPages(options?: FetchCustomPagesOptions): Promise<CustomPageEntry[]>
  loadThemeSettings(strategy?: CachingStrategy): Promise<WeaverseThemeSettingsResponse>
  loadPage(params?: LoadPageParams): Promise<WeaverseLoaderData | null>
  execComponentLoader(item: WeaverseComponentData): Promise<WeaverseComponentData>
  generateFallbackPage(message: string): WeaversePageData
}

type WeaverseClientArgs = {
  storefront: WeaverseStorefront // Hydrogen 2026.10 Storefront API client
  locale?: WeaverseI18n // defaults to `storefront.i18n`
  env: WeaverseEnv
  waitUntil?: (promise: Promise<unknown>) => void
  customerAccount?: unknown
  components: WeaverseComponent[]
  themeSchema: WeaverseThemeSchema
  request: Request
  cache: Cache
  projectId?: string | (() => string) | (() => Promise<string>)
  fetchTimeoutMs?: number
  throwPageLoadFailures?: boolean
}
```

* `locale` selects the content locale, the Translation Manager overrides (`${language}-${country}`, lowercased) and the locale Studio reads, so include `pathPrefix`. Pass it when the Storefront client's `i18n.language` is a Shopify `LanguageCode` that differs from the market's public language, such as `ZH_TW` for a Traditional Chinese Hong Kong market. Added in `@weaverse/hydrogen` 6.1.0.
* `throwPageLoadFailures: true` makes `loadPage()` reject with a `WeaverseLoadError` when the content API is unavailable, instead of resolving to `null`, so a route can answer an outage differently from a missing page.

`API` is the current API version segment (`'v1'`), not a complete endpoint URL.

## Methods

### `fetchWithCache`

Fetch data through Hydrogen's cache integration:

```typescript theme={null}
fetchWithCache<T>(
  url: string,
  options?: RequestInit & {
    cacheTarget?: BuilderApiCacheTarget
    strategy?: CachingStrategy
  }
): Promise<T>
```

```typescript theme={null}
export async function loader({ weaverse }: WeaverseComponentLoaderArgs) {
  const products = await weaverse.fetchWithCache<Product[]>(
    'https://api.example.com/products',
    {
      strategy: {
        maxAge: 60,
        staleWhileRevalidate: 600,
      },
    }
  )

  return { products }
}
```

Use `strategy`, not the Fetch API `cache` property, for Hydrogen cache-control options.

### `loadThemeSettings`

```typescript theme={null}
loadThemeSettings(
  strategy?: CachingStrategy
): Promise<WeaverseThemeSettingsResponse>
```

The response can contain:

```typescript theme={null}
type WeaverseThemeSettingsResponse = {
  theme?: WeaverseThemeSettings
  schema?: WeaverseThemeSchema
  publicEnv?: PublicEnv
  staticContent?: Record<string, unknown>
  merchantOverrides?: Record<string, unknown>
  _error?: string
  _loadFailed?: boolean
}
```

Return the complete response under `weaverseTheme` from the root loader so `withWeaverse` can initialize theme and translation stores:

```typescript theme={null}
export async function loader({ context }: Route.LoaderArgs) {
  return {
    weaverseTheme: await context.weaverse.loadThemeSettings(),
  }
}
```

Read settings directly from the response with `response.theme`.

### `loadPage`

```typescript theme={null}
loadPage(params?: {
  type?: PageType
  locale?: string
  handle?: string
  strategy?: CachingStrategy
  projectId?: string
}): Promise<WeaverseLoaderData | null>
```

#### `type`

Supported `PageType` values:

* `'*'`
* `'INDEX'`
* `'PRODUCT'`
* `'ALL_PRODUCTS'`
* `'COLLECTION'`
* `'COLLECTION_LIST'`
* `'PAGE'`
* `'BLOG'`
* `'ARTICLE'`
* `'CUSTOM'`

When omitted, the content service resolves the page from the request URL and project configuration.

#### `locale`

An optional BCP 47 locale override such as `en-US`, `sv-SE`, or `fr-CA`. The value is forwarded unchanged. When omitted, the request uses the client's `locale` argument, or `storefront.i18n` when that isn't set; `loadPage()` does not implement its own URL-prefix detection or `en-us` fallback.

#### `handle`

The resource or custom-page handle used with page types such as `PRODUCT`, `COLLECTION`, `PAGE`, `BLOG`, and `ARTICLE`.

#### `projectId`

Overrides the client's resolved project ID for this request. Constructor-level `projectId` can also be a synchronous or asynchronous function for multi-project storefronts.

#### `strategy`

A Hydrogen `CachingStrategy` (create one with `Cache` from `@shopify/hydrogen`), for example:

```typescript theme={null}
strategy: {
  mode: 'public',
  maxAge: 3600,
  staleWhileRevalidate: 86400,
  sMaxAge: 7200,
  staleIfError: 604800,
}
```

#### Example

```typescript theme={null}
export async function loader({ context, params }: Route.LoaderArgs) {
  const weaverseData = await context.weaverse.loadPage({
    type: 'PRODUCT',
    handle: params.productHandle,
    locale: 'en-US',
  })

  if (!weaverseData) {
    throw new Response('Weaverse page load failed', { status: 500 })
  }

  return { weaverseData }
}
```

A missing page payload is normalized into a fallback page. `null` indicates that loading or validation failed; do not treat it as a reliable page-not-found signal.

### `fetchCustomPages`

```typescript theme={null}
fetchCustomPages(options?: {
  limit?: number
  locale?: string
}): Promise<CustomPageEntry[]>
```

Fetches published custom-page entries for sitemap and route-generation workflows.

```typescript theme={null}
const pages = await context.weaverse.fetchCustomPages({
  locale: 'en-US',
  limit: 100,
})
```

### `execComponentLoader`

```typescript theme={null}
execComponentLoader(
  item: WeaverseComponentData
): Promise<WeaverseComponentData>
```

Runs the registered loader for one component and attaches its loader data. `loadPage()` calls this internally.

### `generateFallbackPage`

```typescript theme={null}
generateFallbackPage(message: string): WeaversePageData
```

Creates the page structure used when the content response does not include page data.

## Related

* [WeaverseHydrogenRoot](https://weaverse.io/docs/api-reference/weaverse-root.md) - Render loader data
* [withWeaverse](https://weaverse.io/docs/api-reference/with-weaverse.md) - Initialize root theme and Studio providers
* [Data Fetching and Caching](https://weaverse.io/docs/development-guide/data-fetching.md) - Component data loading


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.