Skip to content
Back to skills

Shopify Hydrogen

ASecurity

Core Shopify Hydrogen APIs — createHydrogenContext, cart handler, CartForm, caching strategies, pagination, SEO, variant selection, analytics, and CSP.

  • 88 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
ai-agentsbashreactnodegitapisecurityperformancedocumentation

Works with

  • cursor
  • cli
  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 22, 2026

npx -y skills add Weaverse/.claude --skill shopify-hydrogen --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Shopify Hydrogen?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Shopify Hydrogen
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/weaverse-shopify-hydrogen/badge)](https://www.skillsdirectory.com/skills/weaverse-shopify-hydrogen)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: shopify-hydrogen
description: "Core Shopify Hydrogen APIs — createHydrogenContext, cart handler, CartForm, caching strategies, pagination, SEO, variant selection, analytics, and CSP."
---

# Shopify Hydrogen

Hydrogen is Shopify's opinionated stack for headless commerce, built on React Router v7. It provides utilities, handlers, and components for building storefronts on top of the Shopify Storefront API.

**All exports come from `@shopify/hydrogen`**, which re-exports everything from `@shopify/hydrogen-react`.

> Source: https://github.com/Shopify/hydrogen/tree/main/packages/hydrogen/src

## Live Documentation

Run these from this skill's own folder; the paths below are relative to the skill root.

For the most up-to-date Hydrogen API docs, use the search script:

```bash
node scripts/search_shopify_docs.mjs "<query>"
```

This queries Shopify's developer docs (`shopify.dev`) directly and returns the latest API references, code examples, and guides for Hydrogen.

**Examples:**
```bash
node scripts/search_shopify_docs.mjs "createHydrogenContext"
node scripts/search_shopify_docs.mjs "CartForm actions"
node scripts/search_shopify_docs.mjs "caching strategies"
node scripts/search_shopify_docs.mjs "getSeoMeta"
node scripts/search_shopify_docs.mjs "Pagination component"
```

For offline/cached reference, see the [references/](#references) folder below.

---

## Key Concepts (Quick Reference)

### createHydrogenContext

The single entry point to set up all Hydrogen services in `server.ts`. Creates and wires together `storefront`, `customerAccount`, and `cart`.

- Required env vars: `PUBLIC_STORE_DOMAIN`, `PUBLIC_STOREFRONT_API_TOKEN`, `PRIVATE_STOREFRONT_API_TOKEN`, `PUBLIC_STOREFRONT_ID`, `PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID`, `SHOP_ID`
- Returns: `{ storefront, customerAccount, cart }`

### Caching Strategies

| Strategy | maxAge | staleWhileRevalidate | Use for |
|----------|--------|----------------------|---------|
| `CacheNone()` | — | — | User-specific or real-time data |
| `CacheShort()` | 1s | 9s | Frequently changing data |
| `CacheLong()` | 1hr | 23hr | Stable data (shop info, menus) |
| `CacheCustom({...})` | custom | custom | Fine-grained control |

### Cart Handler

`createCartHandler` provides all cart operations: `get`, `create`, `addLines`, `updateLines`, `removeLines`, `updateDiscountCodes`, `addGiftCardCodes`, `updateBuyerIdentity`, `updateNote`, `setMetafields`, and more.

### CartForm

Form component for cart mutations. Uses `CartForm.ACTIONS` enum (`LinesAdd`, `LinesUpdate`, `LinesRemove`, `DiscountCodesUpdate`, etc.) and submits via React Router's `useFetcher`.

### useOptimisticCart

Applies pending cart mutations locally for instant UI feedback. Requires `selectedVariant` in `LinesAdd` inputs.

### Pagination

`getPaginationVariables(request, { pageBy })` + `<Pagination connection={...}>` component. GraphQL query must include `pageInfo { hasPreviousPage hasNextPage startCursor endCursor }`.

### SEO

`getSeoMeta(...)` generates React Router `meta` arrays. Supports `title`, `titleTemplate`, `description`, `url`, `media`, `jsonLd`, `robots`, `alternates`. `jsonLd` is concatenated across routes.

### Sitemaps

`getSitemapIndex` + `getSitemap` — two-level sitemap generation. Requires Storefront API 2024-10+.

### Content Security Policy

`createContentSecurityPolicy({ shop: { checkoutDomain, storeDomain } })` returns `{ nonce, header, NonceProvider }`.

---

## References

For offline/cached reference when the search script is unavailable:

| File | Contents |
|------|----------|
| [references/01-setup.md](references/01-setup.md) | Full `server.ts` setup, env vars, session, `createHydrogenContext` options |
| [references/02-caching.md](references/02-caching.md) | Cache strategies, `AllCacheOptions` type, `generateCacheControlHeader` |
| [references/03-cart.md](references/03-cart.md) | Cart route setup, `CartForm` examples, `useOptimisticCart` patterns |
| [references/04-ssr-performance.md](references/04-ssr-performance.md) | SSR bundle diet (worker inlines dynamic imports — `resolveId` stub pattern), bundle audit, TTFB measurement methodology |

Files in this skill

  • SKILL.md4 KB
  • references/01-setup.md5.1 KB
  • references/02-caching.md2.9 KB
  • references/03-cart.md9.9 KB
  • references/04-ssr-performance.md3.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.