Skip to main content

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, 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:
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 for every schema property and Input Settings for every input type.

2. Write the component

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).
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.
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:
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.

Server registry

The server registry holds the same schemas plus the loaders. It never renders, so its default is a stub:
Pass this array to createWeaverseNextServerClient as components. The server registry imports schema files only, never a component module.
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: 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:
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.

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.
  • 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:
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 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:
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:

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

Next Steps

Component Schema

Every schema property, with examples.

Input Settings

Every input type and what it returns.

Data Fetching

Loaders, the commerce context and caching.

Rendering Pages

Render Weaverse pages in App Router routes.
Last modified on November 30, 2026