> ## 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

> Request-scoped client for loading Weaverse pages and theme settings in Hydrogen.

Create one client from the Hydrogen app context, then call
[WeaverseClient.loadPage](https://weaverse.io/docs/api-reference/classes/WeaverseClient.md#loadpage) from route loaders and
[WeaverseClient.loadThemeSettings](https://weaverse.io/docs/api-reference/classes/WeaverseClient.md#loadthemesettings) from the root loader.

Also runs registered component loaders and routes Builder API requests
through Hydrogen's cache. `API` is the API version segment (`'v1'`), not a
complete endpoint URL.

The constructor checks the project ID, whatever `throwPageLoadFailures` is
set to: it throws a [WeaverseError](https://weaverse.io/docs/api-reference/classes/WeaverseError.md) with code `MISSING_PROJECT_ID`
when none resolves (`?weaverseProjectId=`, the `projectId` argument or
`WEAVERSE_PROJECT_ID`), `INVALID_PROJECT_ID` for a malformed `projectId`,
and `ASYNC_PROJECT_ID` for an `async` `projectId` function, which must be
awaited before you create the client.

Create the client once per request in the app context, from the request's
Hydrogen 2026.10 Storefront API client. `createRequestStorefront`,
`createCustomerAccount`, `AppSession` and `resolveRequestLocale` are app
code (see the v6 migration guide); `server.ts` copies the returned object
onto React Router's context, so loaders read `context.weaverse`.

```ts
// app/.server/context.ts
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.locale`
    locale: resolveRequestLocale(request),
    // Optional: reject with WeaverseLoadError on a failed load instead of resolving to null
    throwPageLoadFailures: true,
  })

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

## Constructor

```typescript
WeaverseClient(args: WeaverseClientArgs): WeaverseClient
```

Creates a request-scoped client from the storefront's request context.

### Parameters

**args** `WeaverseClientArgs` *required*

### Returns

`WeaverseClient`

## Properties

**API** `"v1"` *required*

Builder API version used by this client.

**basePageConfigs** `Omit\<WeaverseProjectConfigs, "requestInfo"\>` *required*

**Type:** `Omit<WeaverseProjectConfigs, "requestInfo">`

Stable project configuration shared by page requests.

**basePageRequestBody** `Omit\<FetchProjectRequestBody, "url"\>` *required*

**Type:** `Omit<FetchProjectRequestBody, "url">`

Stable request body fields shared by page requests.

**cache** `CacheInstance` *required*

Cache storage supplied by the Hydrogen runtime.

**components** `WeaverseComponent\<any\>[]` *required*

**Type:** `WeaverseComponent<any>[]`

Components registered for page rendering and component loaders.

**configs** `WeaverseProjectConfigs` *required*

Resolved project and rendering-mode configuration.

**customerAccount** `unknown` *required*

Customer Account API client, when the storefront passes one.

**env** `WeaverseEnv` *required*

Runtime environment variables.

**request** `Request` *required*

Incoming request associated with this client instance.

**storefront** `WeaverseStorefront` *required*

Hydrogen Storefront API client and locale context.

**themeSchema** `WeaverseThemeSchema` *required*

Theme schema used for defaults and Studio editing.

**waitUntil** `(promise: Promise\<unknown\>) =\> void | undefined` *required*

Background execution hook supplied by the runtime.

## Methods

### execComponentLoader()

```typescript
execComponentLoader(item: WeaverseComponentData): Promise<WeaverseComponentData>
```

Executes the registered loader for one component and attaches its result.

#### Parameters

**item** `WeaverseComponentData` *required*

#### Returns

`Promise<WeaverseComponentData>`

### fetchCustomPages()

```typescript
fetchCustomPages(opts?: FetchCustomPagesOptions): Promise<CustomPageEntry[]>
```

Fetch the route metadata of every custom page assigned in the project
(`path`, `lastModified`, `changeFrequency`, `priority`, plus `locale`,
`market` and `scope`, which tell global, locale and market assignments
apart), for sitemap and route generation. Paginates automatically. Rejects with a [WeaverseLoadError](https://weaverse.io/docs/api-reference/classes/WeaverseLoadError.md) when any
page of results cannot be loaded, so a sitemap route can answer 5xx
instead of serving a partial or empty sitemap that search engines cache.

The list is not filtered by publication state, so an entry is not proof
that the page is published. Apply your own publication policy before you
add a route to a public sitemap.

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

#### Parameters

**opts** `FetchCustomPagesOptions`

#### Returns

`Promise<CustomPageEntry[]>`

### fetchWithCache()

```typescript
fetchWithCache(url: string, options?: WeaverseFetchWithCacheOptions): Promise<T>
```

Fetch data with caching support for both design mode and production.
Uses direct fetch in design mode, Hydrogen's cached fetch in production.
Automatically includes projectId in cache key for multi-project isolation.

Pass Hydrogen cache-control options as `strategy`, not the Fetch API
`cache` property.

Hydrogen's cache is skipped in design mode, in revision preview, and for
requests to the Weaverse public API proxy
(`https://api.weaverse.io/api/public/...` by default). The proxy owns the
freshness of Weaverse data, so `strategy` applies to third-party URLs and
to a self-hosted `WEAVERSE_HOST` that serves the API itself.

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

#### Parameters

**url** `string` *required*

The URL to fetch from

**options** `WeaverseFetchWithCacheOptions`

Fetch options including optional cache strategy

#### Returns

`Promise<T>`

Promise resolving to the fetched data

### generateFallbackPage()

```typescript
generateFallbackPage(message: string): WeaversePageData
```

Generate fallback page with default structure when page data is unavailable.
Used internally when API returns no page or when page needs default content.

#### Parameters

**message** `string` *required*

Custom message to display in the fallback page

#### Returns

`WeaversePageData`

WeaversePageData with single main component containing the message

### loadPage()

```typescript
loadPage(params?: LoadPageParams): Promise<WeaverseLoaderData | null>
```

Load page data from Weaverse API with optional route-level project override.
Fetches page content, executes component loaders, and handles empty items fallback.

What `loadPage()` resolves to:

* A page when one is assigned to the route.
* A fallback page with `isFallback: true` when the project loads but no
  page is assigned to the route. It is not `null`. Answer it with a 404 on
  the live storefront, but keep it in design mode, where the merchant
  builds on it in Studio.
* `null` when the Weaverse API answers 404 (for example, the project does
  not exist), and, by default, when the load fails (invalid per-call
  `projectId`, network error, timeout, error status or error body). The
  failure is logged.
* The fallback page, by default, when the API answers 200 with a body that
  is not a page envelope (for example `{}`).
* A rejection with a [WeaverseLoadError](https://weaverse.io/docs/api-reference/classes/WeaverseLoadError.md) instead of `null` for a
  failed load when the client sets `throwPageLoadFailures: true`.

`locale` is forwarded unchanged; when omitted, the request uses the
client's `locale` argument, or `storefront.locale`. `strategy` takes effect
only when the page request goes through Hydrogen's cache: requests to the
default Weaverse public API proxy skip it.

```ts
// Route-level project override
const data = await weaverse.loadPage({
  type: 'PAGE',
  handle: 'about',
  projectId: 'campaign-project-123',
})
```

Answer a missing page with a 404:

```ts
// app/routes/($locale).pages.$handle.tsx
export async function loader({ context, params }: Route.LoaderArgs) {
  const weaverseData = await context.weaverse.loadPage({
    type: 'PAGE',
    handle: params.handle,
  })
  // `null`, or the fallback page outside design mode, means no page
  if (
    !weaverseData ||
    (weaverseData.isFallback && !weaverseData.configs.isDesignMode)
  ) {
    throw new Response(null, { status: 404 })
  }
  return { weaverseData }
}
```

#### Parameters

**params** `LoadPageParams`

Optional page loading parameters

#### Returns

`Promise<WeaverseLoaderData | null>`

Promise resolving to page data or null on error

### loadThemeSettings()

```typescript
loadThemeSettings(strategy?: CachingStrategy): Promise<WeaverseThemeSettingsResponse>
```

Load theme settings from Weaverse API with fallback to schema defaults.
Merges remote settings with local theme schema and handles design mode serialization.

Return the whole response under `weaverseTheme` from the root loader so
[withWeaverse](https://weaverse.io/docs/api-reference/functions/withWeaverse.md) can initialize the theme settings and translation
stores. Read setting values from `response.theme`.

```ts
// app/root.tsx
export async function loader({ context }: Route.LoaderArgs) {
  return { weaverseTheme: await context.weaverse.loadThemeSettings() }
}
```

#### Parameters

**strategy** `CachingStrategy`

Optional cache strategy override

#### Returns

`Promise<WeaverseThemeSettingsResponse>`

Promise resolving to theme settings response


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