🚀 Important: React Router v7 Migration Weaverse v5 has migrated to React Router v7, aligning with Shopify Hydrogen’s May 2025 release. Choose the correct version:If you’re unsure which version you have, check your
- Hydrogen with React Router v7: Use
@weaverse/hydrogen@5.0.0+
(latest)- Hydrogen with Remix: Use
@weaverse/hydrogen@4.x
(legacy support)package.json
forreact-router
vs@remix-run/react
dependencies.
Prerequisites
Before you start, ensure you have:- An existing Shopify Hydrogen project set up and running locally.
- Node.js (version recommended by Hydrogen) and npm/yarn installed.
- Your Hydrogen project connected to your Shopify store.
- A Weaverse account and a Weaverse Project created for your storefront.
- Basic familiarity with Hydrogen concepts and either:
- React Router v7 (for Hydrogen 2025.5.0+) - recommended for new projects
- Remix (for older Hydrogen versions) - legacy support
Migration Consideration
If you’re currently using Hydrogen with Remix and want to upgrade to React Router v7, consider following the official Shopify migration guide first, then install Weaverse v5. Alternatively, you can use Weaverse v4 with your current Remix setup.Step 1: Install Weaverse SDK
Navigate to your Hydrogen project directory in your terminal and add the Weaverse Hydrogen SDK.For Hydrogen with React Router v7 (Recommended)
If your project uses React Router v7 (Hydrogen 2025.5.0+), install the latest version:For Hydrogen with Remix (Legacy)
If your project still uses Remix (Hydrogen versions before 2025.5.0), install v4:How to Check Your Hydrogen Version
Check yourpackage.json
dependencies:
- React Router v7: Contains
react-router
and@shopify/hydrogen@2025.5.0+
- Remix: Contains
@remix-run/react
and@shopify/remix-oxygen
Step 2: Configure Environment Variables
Weaverse needs credentials to connect to your project. Add the following variables to your.env
file (create one if it doesn’t exist) at the root of your Hydrogen project:
"your-project-id"
and "your-api-key"
with the actual credentials found in your Weaverse project settings.
Step 3: Set Up Core Weaverse Files
Create aweaverse
folder inside your app
directory (app/weaverse/
). This folder will house Weaverse-specific configurations and utilities.
1. Theme Schema (~/weaverse/schema.server.ts
)
This file defines your theme’s metadata (name, author, version), global settings schema (which populates the Theme Customizer in Weaverse Studio), and i18n configurations.
2. Global Styles (~/weaverse/style.tsx
)
This component applies global CSS variables based on the theme settings defined in schema.server.ts
and configured in Weaverse Studio.
3. Component Registration (~/weaverse/components.ts
)
This is the central file where you register all the React components that you want to be available for use within the Weaverse editor.
4. WeaverseContent Component (~/weaverse/index.tsx
)
This component renders the Weaverse content by using the WeaverseHydrogenRoot
component and passing the registered components.
5. Content Security Policy (CSP) (~/weaverse/csp.ts
)
This utility helps configure the Content Security Policy headers required for the Weaverse editor iframe to function correctly.
Step 4: Add Weaverse Client to Hydrogen App Context
A crucial step is to initialize the Weaverse client and add it to your Hydrogen app load context. This allows your application to access Weaverse functionality throughout your routes.1. Update Your Context File
Modify your app context file (usuallyapp/lib/context.ts
or similar) to initialize and include the WeaverseClient:
Note: The code examples below show the React Router v7 version (Weaverse v5). If you’re using Remix with Weaverse v4, the import paths will be @shopify/remix-oxygen
instead of the native React Router modules.
- Imports the
WeaverseClient
from the Weaverse Hydrogen SDK - Imports your theme schema and components from the files created in the previous step
- Initializes a new
WeaverseClient
instance with necessary context - Adds the Weaverse client to your app context, making it available via
context.weaverse
in loaders and actions
2. Ensure Server Entry Point Uses Updated Context
Your server entry point (typicallyserver.ts
) should already use your context function:
Step 5: Integrate Weaverse into Your Application
Now, let’s modify your existing Hydrogen files to enable Weaverse.1. Update CSP in entry.server.tsx
Modify your app/entry.server.tsx
to use the getWeaverseCsp
function.
2. Update Root Component
The root component needs to be wrapped withwithWeaverse
to enable the Weaverse functionality. Here’s how to implement it in your app/root.tsx
file:
withWeaverse
HOC doesn’t require components to be passed directly here. The components are imported from the components.ts
file and used by the WeaverseContent
component.
3. Adapt Route Components
For each route you want to make editable with Weaverse (e.g., Homepage, Product pages, Collection pages, Custom pages), you need to:- Import the
WeaverseContent
component - Use it in your route component
- Load the necessary Weaverse data in your loader
app/routes/($locale)._index.tsx
):
app/routes/($locale).products.$productHandle.tsx
):
WeaverseContent
component will automatically render the content based on the page type and handle, using the components registered in your components.ts
file.
Step 6: Run and Connect
- Start your dev server:
npm run dev
- Open Weaverse Studio: Go to your project in Weaverse.
- Update Preview URL: In Weaverse Studio, update the preview URL in your project settings to your local dev server URL (usually
http://localhost:3000
).
Next Steps
- Create Custom Components: Learn how to build your own React components and make them editable in Weaverse. ([Link to relevant doc when available])
- Explore Theme Settings: Customize the global styles defined in
schema.server.ts
via the Weaverse Studio. - Utilize Weaverse Features: Explore Custom Pages, Custom Templates, AI features, and more.