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

# Creating Components

> Build Weaverse sections for a Next.js storefront with @weaverse/hydrogen/next, from the schema and the client component to registration and loaders.

# Creating Components

A Weaverse component in a Next.js storefront has three parts:

* a **schema** that tells Studio what the component is called and which settings merchants can edit,
* a **Client Component** that renders those settings,
* an optional **loader** that fetches data on the server.

This guide builds a hero banner from scratch, registers it, and then covers typing, child components and data. Examples follow [Forward](https://weaverse.io/docs/hydrogen-themes/forward.md), the Weaverse Next.js starter theme.

## File structure

Keep each part of a component in its own file:

* sections/
  * hero-banner/
    * schema.ts
    * index.tsx
    * loader.ts
* weaverse/
  * components.ts
  * server-components.ts

- `schema.ts`: the schema, created with `createSchema()`. It holds plain data, so both server and client code can import it.
- `index.tsx`: the component, a `'use client'` module. It re-exports the schema so the module is a complete registry entry.
- `loader.ts` (optional): server-side data loading.
- `weaverse/components.ts`: the client registry, which the renderer uses to render sections.
- `weaverse/server-components.ts`: the server registry, which holds schemas and loaders.

The split comes from React Server Components. `WeaverseNextRenderer` is a Client Component, so every section it renders is a Client Component too. Loaders run on the server and often read secrets, so they must never be bundled for the browser. A separate schema file lets the server registry use the schema without importing the component.

## 1. Define the schema

Import `createSchema` from `@weaverse/hydrogen/next`:

```ts theme={null}
// sections/hero-banner/schema.ts
import { createSchema } from '@weaverse/hydrogen/next'

export let schema = createSchema({
  type: 'hero-banner',
  title: 'Hero banner',
  childTypes: ['heading', 'paragraph'],
  settings: [
    {
      group: 'Content',
      inputs: [
        {
          type: 'text',
          name: 'buttonText',
          label: 'Button text',
          defaultValue: 'Shop now',
        },
        {
          type: 'url',
          name: 'buttonLink',
          label: 'Button link',
          defaultValue: '/collections/all',
        },
      ],
    },
    {
      group: 'Design',
      inputs: [
        { type: 'image', name: 'backgroundImage', label: 'Background image' },
        {
          type: 'range',
          name: 'overlayOpacity',
          label: 'Overlay opacity',
          defaultValue: 40,
          configs: { min: 0, max: 100, step: 5, unit: '%' },
        },
      ],
    },
  ],
  presets: {
    buttonText: 'Shop now',
    buttonLink: '/collections/all',
    children: [
      { type: 'heading', content: 'Welcome to our store' },
      { type: 'paragraph', content: 'Discover products made to last.' },
    ],
  },
})
```

Keep the schema module free of client-only code. Importing a type from the component file is fine (`import type` is erased at build time), but importing the component itself would pull a Client Component into the server registry.

See [Component Schema](https://weaverse.io/docs/nextjs/component-schema.md) for every schema property and [Input Settings](https://weaverse.io/docs/nextjs/input-settings.md) for every input type.

## 2. Write the component

```tsx theme={null}
// sections/hero-banner/index.tsx
'use client'

import type {
  WeaverseImage,
  WeaverseNextComponentProps,
} from '@weaverse/hydrogen/next'
import Image from 'next/image'
import Link from 'next/link'

interface HeroBannerProps extends WeaverseNextComponentProps {
  buttonText?: string
  buttonLink?: string
  // An `image` input returns an image object, not a URL string
  backgroundImage?: WeaverseImage
  overlayOpacity?: number
}

function HeroBanner({
  buttonText,
  buttonLink,
  backgroundImage,
  overlayOpacity = 40,
  children,
  ...rest
}: HeroBannerProps) {
  return (
    <section
      {...rest}
      className="relative flex min-h-[500px] items-center justify-center"
    >
      {backgroundImage?.url && (
        <Image
          src={backgroundImage.url}
          alt={backgroundImage.altText ?? ''}
          fill
          sizes="100vw"
          className="object-cover"
          priority
        />
      )}
      <div
        className="absolute inset-0 bg-black"
        style={{ opacity: overlayOpacity / 100 }}
      />
      <div className="relative z-10 mx-auto max-w-4xl px-4 text-center text-white">
        {children}
        {buttonText && buttonLink && (
          <Link
            href={buttonLink}
            className="mt-8 inline-block rounded-lg bg-white px-8 py-3 font-semibold text-black"
          >
            {buttonText}
          </Link>
        )}
      </div>
    </section>
  )
}

export default HeroBanner

export { schema } from './schema'
```

What matters here:

* **`'use client'`** at the top. Every registered component is a Client Component.
* **A default export** for the component and a **named `schema` export**. Together they form a registry entry.
* **Spread the remaining props onto the outermost element.** The runtime passes `data-wv-id`, `data-wv-type`, `id` and `className` with your settings. Studio uses them to outline, select and reorder the section. Without them, the section renders but merchants can't edit it.
* **`children`** renders the child components merchants add in Studio (here, the `heading` and `paragraph` from the presets).

> [!TIP]
>
> The runtime passes every setting as a prop, so whatever you don't destructure ends up in `rest` and on the DOM element, where React warns about unknown attributes. Forward avoids this with a small `elementAttributes()` helper that forwards only `data-wv-id`, `data-wv-type`, `id` and `aria-*` attributes. See [`sections/weaverse-element.ts`](https://github.com/Weaverse/forward/blob/main/src/sections/weaverse-element.ts).

`next/image` only loads images from hosts your `next.config` allows. Images from the `image` input are served from `cdn.shopify.com`, so add it to `images.remotePatterns`.

## 3. Register the component

A component has to be in both registries.

### Client registry

The client registry is what `WeaverseNextRenderer` renders. Import each section as a namespace, so its default export and `schema` come together:

```ts theme={null}
// weaverse/components.ts
'use client'

import type { WeaverseNextComponent } from '@weaverse/hydrogen/next'
import * as HeroBanner from '@/sections/hero-banner'
import * as FeaturedProducts from '@/sections/featured-products'

// A section's props are narrower than the runtime's generic prop bag, so widen
// the component type once here instead of loosening every section's props.
function entry(module: {
  default: unknown
  schema: WeaverseNextComponent['schema']
}): WeaverseNextComponent {
  return {
    default: module.default as WeaverseNextComponent['default'],
    schema: module.schema,
  }
}

export let components: WeaverseNextComponent[] = [
  entry(HeroBanner),
  entry(FeaturedProducts),
]
```

`WeaverseNextComponent['default']` is typed for any props the runtime might pass, so assigning a component with its own props interface directly to `WeaverseNextComponent[]` fails type checking. The `entry()` helper from Forward widens the type in one place.

Pass this array to `createWeaverseNextClient` in your client boundary. See [Rendering Pages](https://weaverse.io/docs/nextjs/rendering-pages.md#the-client-boundary).

### Server registry

The server registry holds the same schemas plus the loaders. It never renders, so its `default` is a stub:

```ts theme={null}
// weaverse/server-components.ts
import 'server-only'

import type { WeaverseNextComponent } from '@weaverse/hydrogen/next'
import { schema as featuredProducts } from '@/sections/featured-products/schema'
import { loader as featuredProductsLoader } from '@/sections/featured-products/loader'
import { schema as heroBanner } from '@/sections/hero-banner/schema'

let LOADERS: Record<string, WeaverseNextComponent['loader']> = {
  'featured-products': featuredProductsLoader,
}

let SCHEMAS = [heroBanner, featuredProducts]

let NO_RENDER = (() => null) as WeaverseNextComponent['default']

export let serverComponents: WeaverseNextComponent[] = SCHEMAS.map(
  (schema) => {
    let loader = LOADERS[schema.type]
    return { default: NO_RENDER, schema, ...(loader && { loader }) }
  }
)
```

Pass this array to `createWeaverseNextServerClient` as `components`. The server registry imports schema files only, never a component module.

> [!WARNING]
>
> Don't import the client registry from the server one, or the reverse. The first pulls every section into the server bundle; the second ships your loaders, queries and credentials to the browser.

Forward keeps the list of schemas in one shared module (`section-schemas.ts`), so the two registries can't drift apart, and checks the client registry against it in a test.

## Typing Props

Schemas are runtime configuration, not a source of TypeScript types. No helper infers props from a schema, so declare an interface for the values your inputs produce and keep it in sync with each input's `name`.

`@weaverse/hydrogen/next` exports the types you need:

| Type | Use it for |
| - | - |
| `WeaverseNextComponentProps<LoaderData>` | Base props of a registered component. The type argument types `loaderData`. |
| `WeaverseImage` | The value of an `image` input |
| `WeaverseVideo` | The value of a `video` input |
| `WeaverseProduct`, `WeaverseCollection`, `WeaverseBlog`, `WeaverseMetaObject` | The value of a resource picker input (`{ id, handle }`) |
| `WeaverseNextComponentLoaderArgs` | The argument of a loader |

Every setting can be empty: a merchant can clear an input in Studio, and an instance saved before you added a setting won't have it. Mark settings optional and handle the empty case instead of throwing.

## Child Components

List the types a component accepts in `childTypes`, then render `children` where they belong:

```tsx theme={null}
function HeroBanner({ children, ...rest }: HeroBannerProps) {
  return (
    <section {...rest}>
      <div className="content">{children}</div>
    </section>
  )
}
```

Child components are registered like any other component. Forward registers shared elements (`heading`, `subheading`, `paragraph`, `button`) once and reuses them in many sections. A type listed in any `childTypes` is hidden from the root **Add Section** picker unless it opts back in. See [Standalone and Nested Components](https://weaverse.io/docs/nextjs/component-schema.md#standalone-and-nested-components).

## Loading Data

A section gets Shopify data in one of two ways:

* **From the route.** On a product, collection, page or article template, the URL decides which resource is shown. The route loads it and passes it to sections through a React context. See [Route data or section loaders](https://weaverse.io/docs/nextjs/rendering-pages.md#route-data-or-section-loaders).
* **From its own loader.** When the merchant picks the resource in Studio, the section loads it on the server.

A loader takes one argument and returns any serializable value. The component receives it as `loaderData`:

```ts theme={null}
// sections/featured-products/loader.ts
import type {
  WeaverseNextComponentLoaderArgs,
  WeaverseProduct,
} from '@weaverse/hydrogen/next'

interface FeaturedProductsData {
  products?: WeaverseProduct[]
}

export async function loader({ data, commerce }: WeaverseNextComponentLoaderArgs) {
  let { products = [] } = data as FeaturedProductsData
  if (products.length === 0) {
    return { products: [] }
  }

  let result = await commerce?.storefront?.query(PRODUCTS_QUERY, {
    variables: { ids: products.map((product) => `gid://shopify/Product/${product.id}`) },
  })
  return { products: (result as ProductsQueryResult | undefined)?.nodes ?? [] }
}

export type FeaturedProductsLoaderData = Awaited<ReturnType<typeof loader>>
```

```tsx theme={null}
// sections/featured-products/index.tsx
'use client'

import type { WeaverseNextComponentProps } from '@weaverse/hydrogen/next'
import type { FeaturedProductsLoaderData } from './loader'

type FeaturedProductsProps =
  WeaverseNextComponentProps<FeaturedProductsLoaderData>

function FeaturedProducts({ loaderData, ...rest }: FeaturedProductsProps) {
  let products = loaderData?.products ?? []
  return <section {...rest}>{/* product cards, or placeholders */}</section>
}

export default FeaturedProducts

export { schema } from './schema'
```

`data` holds the item's settings merged over the schema defaults. The registry types it as `unknown`, so narrow it with your settings interface. The component imports only the loader's type, which is erased at build time, so the loader stays on the server.

Add the loader to the server registry, and set `shouldRevalidate: true` on the inputs it reads so Studio re-runs it when the merchant changes them. [Data Fetching](https://weaverse.io/docs/nextjs/data-fetching.md) covers loader arguments, the commerce context, markets and caching.

### Empty States

Loaders finish on the server before the page renders, so an empty `loaderData` never means "still loading". It means the merchant hasn't picked anything yet, or the loader found nothing. Render placeholders in the section's real layout, so a freshly added section still looks like itself in Studio:

```tsx theme={null}
'use client'

import { IMAGES_PLACEHOLDERS } from '@weaverse/hydrogen/next'

function FeaturedProducts({ loaderData, ...rest }: FeaturedProductsProps) {
  let products = loaderData?.products ?? []
  return (
    <section {...rest}>
      {products.length > 0
        ? products.map((product) => <ProductCard key={product.id} product={product} />)
        : <ProductCardPlaceholder image={IMAGES_PLACEHOLDERS.product_1} />}
    </section>
  )
}
```

`IMAGES_PLACEHOLDERS` maps names (`product_1`, `collection_1`, `banner_1`, ...) to URLs of Weaverse's SVG placeholder art on Shopify's CDN. If your `next.config` `images.remotePatterns` allows only your own shop's files, render them with `unoptimized` on `next/image`, as Forward's `kit-callout` and `product-spotlight` sections do.

## Reading Theme Settings

Global values such as colors, fonts and page width live in theme settings, not in each section. Read them with [`useThemeSettings`](https://weaverse.io/docs/nextjs/api/next/functions/useThemeSettings):

```tsx theme={null}
'use client'

import { useThemeSettings } from '@weaverse/hydrogen/next'

function PromoBar(props: PromoBarProps) {
  let { pageWidth } = useThemeSettings<{ pageWidth?: number }>()
  // ...
}
```

## Common Issues

**The component renders but can't be selected in Studio.** The runtime props aren't on the outermost DOM element. Spread them (or Forward's `elementAttributes(rest)`) onto it, and don't return `null` or a fragment as the root.

**The component is missing from Studio.** It isn't in the client registry, or its `type` duplicates another component's. Every `type` must be unique.

**The loader never runs.** It isn't in the server registry, or it is keyed under a different `type` than the schema's.

**Picking a new product shows stale data.** The input the loader reads doesn't have `shouldRevalidate: true`, or the revalidation route is missing. See [Per-item revalidation](https://weaverse.io/docs/nextjs/studio.md#per-item-revalidation).

**Build error about `server-only` or a server module in a Client Component.** A section, or the client registry, imports a loader or a server-only data module. Import only the loader's type from the component.

**The component works nested but is missing from Add Section.** Its type is in another component's `childTypes`. See [Standalone and Nested Components](https://weaverse.io/docs/nextjs/component-schema.md#standalone-and-nested-components).

## Next Steps

> [card] [Component Schema](https://weaverse.io/docs/nextjs/component-schema.md)
>
> Every schema property, with examples.

> [card] [Input Settings](https://weaverse.io/docs/nextjs/input-settings.md)
>
> Every input type and what it returns.

> [card] [Data Fetching](https://weaverse.io/docs/nextjs/data-fetching.md)
>
> Loaders, the commerce context and caching.

> [card] [Rendering Pages](https://weaverse.io/docs/nextjs/rendering-pages.md)
>
> Render Weaverse pages in App Router routes.


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