Skip to main content

Overview

@weaverse/hydrogen is a crucial package within the Weaverse ecosystem, designed to facilitate the integration of Shopify Hydrogen (React Router) and Next.js storefronts with the Weaverse CMS. It leverages @weaverse/react for rendering content and provides a client for easy setup and data fetching from Weaverse CMS.

Key Features

  • Weaverse Client Integration: Enables seamless integration with Weaverse CMS, allowing for efficient data fetching and rendering in Hydrogen and Next.js storefronts.
  • Dynamic Data Fetching: Fetch and render page data and global theme settings server-side, ensuring dynamic and consistent content delivery.
  • Component Registration and Rendering: Register React components with Weaverse and render them using the WeaverseHydrogenRoot component.
  • Flexible Schema Definition: Define behavior and interactivity of components within Weaverse Studio through the createSchema() function.
  • Customizable Input Settings: Specify configurations for merchant-customizable component settings in Weaverse Studio.

Image focal points

WeaverseImage supports optional metadata for each image input/usage:
Coordinates are finite numbers from 0 to 1, measured from the original image’s top-left corner. The example identifies a point 80% across and 30% down. The same file can have different points in separate inputs; this metadata does not change the Shopify file or generate a cropped asset. The type is also available through @weaverse/core and @weaverse/react. Themes must apply the metadata to their image renderer. For an image filling a fixed frame with object-fit: cover, convert it to CSS percentages:
Apply the style to the actual image element, including when using an image component wrapper. A valid focal point takes precedence over the existing image position; without it, preserve the theme’s current position or default. Reset by removing focalPoint, and discard the old point when selecting a different image. The percentage position aligns the chosen image point with the same relative position in its frame; it does not necessarily center the point or keep the entire subject visible at every aspect ratio. The SDK preserves image objects through page loading, component props, and theme settings. It does not interpret these generic content objects as validated image values. Studio must validate finite coordinates within [0, 1] before saving editor input. @weaverse/schema validates an image input’s defaultValue.focalPoint when its authoring validators run; legacy string URLs and image defaults without a focal point remain accepted. createSchema reports authoring problems in development, while parseSchema rejects invalid schemas. This does not validate arbitrary persisted data or component preset values. Release the updated Schema package and the Core/React/Hydrogen package group before consumers adopt this contract; update the usual dependency pins as part of that release. The Studio UI is tracked in builder#3043, and Pilot rendering examples in pilot#176. Upgrading the SDK alone does not add editor controls or change theme rendering.

Installation

react, react-dom (19 or later) and react-router (7 or 8) are peer dependencies: the SDK uses your app’s copies, so install them in the storefront itself.

Setup and Usage

Weaverse Client Setup

@weaverse/hydrogen 6 requires @shopify/hydrogen 2026.10 or later, wired through React Router middleware (future.v8_middleware). Hydrogen 2026.4 and earlier use @weaverse/hydrogen 5. Create one client per request from the request-scoped Storefront API client and expose it to loaders as context.weaverse. Hydrogen 2026.10 has no createHydrogenContext(), so the app builds its per-request context itself (this is what the Pilot theme does in app/.server/context.ts, which server.ts copies onto React Router’s context):
loadPage() resolves to null when the project does not exist, and to a placeholder page with isFallback: true when nothing is assigned at the URL. Studio edits that placeholder in design mode; outside design mode a route usually answers it with a 404. storefront.locale selects the content locale, including its pathPrefix. When a market’s Shopify LanguageCode differs from the locale Weaverse keys its translations by (for example ZH_TW for a Traditional Chinese Hong Kong market), pass the market as locale instead of relabeling the storefront client. It sets the Translation Manager locale, the locale sent with page requests and the requestInfo.i18n Studio reads (the wire field keeps the name i18n), while the Storefront API keeps its own locale:
Section loaders receive the same client as weaverse, so they query the Storefront API with weaverse.storefront.graphql(QUERY, { variables, cache }).

Data Fetching and Rendering

Use the Weaverse Client to fetch data such as page content and global theme settings:
Implement the WeaverseHydrogenRoot component to render the fetched content:

Handling Load Failures

By default loadPage() resolves to null both when the project does not exist and when the Weaverse API could not answer, so a route can only answer 404. Create the client with throwPageLoadFailures: true to tell them apart:
error.kind is unavailable (timeout, network error or transient status after the built-in retry), invalid-response (a successful response that is not a page) or configuration (missing or invalid project ID, or a refused request). A missing project still resolves to null, and a URL with no assigned page still resolves to a fallback page, so design mode is unchanged. loadThemeSettings() never throws. When settings cannot be loaded, or the API answers without a theme field, it returns schema defaults with _loadFailed: true; check that flag before treating the settings as the merchant’s.

Content Security Policy

getWeaverseStudioCspDirectives(request) returns the CSP sources Weaverse Studio needs for the current request. Pass it to Hydrogen’s createContentSecurityPolicy (2026.10.3+), which extends its defaults with each array:
It returns {} for normal visitors. Inside Studio it allows the Studio origin to embed the page and serve the bridge script, plus 'unsafe-eval' in design mode. A weaverseHost query that is not a trusted Weaverse origin is ignored. Self-hosted or staging Studio deployments outside weaverse.io / weaverse.dev get {}, like the bridge loader; add their origin to your own directives. Next.js themes import it from @weaverse/hydrogen/next/server. Merge in your own theme sources (video embeds, analytics, fonts) yourself.

Defining Component Schema

Define your component’s schema to control its behavior and interactivity within Weaverse Studio:

Customizing Input Settings

Customize input settings for merchant-adjustable component configurations in Weaverse Studio:

Multi-Project Architecture (v5.7.2+)

Dynamically route different requests to different Weaverse projects based on domain, subdomain, cookies, headers, or any custom logic.

Environment Variables Setup

Use Case 1: Domain-Based Routing (Multi-Market)

Serve different content per country domain without changing any route files:

Use Case 2: Route-Level Overrides

Override the project for specific routes (e.g., campaign landing pages): The returned configs.projectId is the route’s project. Section loaders still receive the client (weaverse.configs.projectId is the client’s default), and theme settings come from the default project.
Dynamically select project based on user cookies:

Contributing

Contributions to the @weaverse/hydrogen package are highly appreciated. Please refer to our contributing guidelines for more details on how to contribute effectively.

License

This package is created by The Weaverse Team (https://weaverse.io) and is licensed under the MIT License.

Classes

Interfaces

Functions

Type Aliases

Variables