Skip to content

Route Hydrogen installs through the @subtextdev/hydrogen wrapper - #22

Open
nrodd wants to merge 3 commits into
mainfrom
hydrogen-wrapper-prompt
Open

Route Hydrogen installs through the @subtextdev/hydrogen wrapper#22
nrodd wants to merge 3 commits into
mainfrom
hydrogen-wrapper-prompt

Conversation

@nrodd

@nrodd nrodd commented Jul 30, 2026

Copy link
Copy Markdown
Member

What

Teaches templates/install-prompt.md the Shopify Hydrogen route. When the agent detects @shopify/hydrogen in dependencies, it installs the @subtextdev/hydrogen wrapper package instead of pasting the raw inline snippet.

Prompt-only change — no wizard code touched, per the "framework logic lives in the agent prompt" architecture.

Changes

  • Step 1 pre-check: @subtextdev/hydrogen in deps now counts as "snippet already installed."
  • Step 2 detection: Hydrogen check added first — Hydrogen apps also carry Remix/React Router and Vite deps, which would otherwise shadow the match.
  • Step 4 framework patterns: a Hydrogen block that derives orgId/region/host overrides from the org snippet already embedded in the prompt (no invented values), then maps each generic step onto the package surface:
    • snippet + CSP nonce → <Subtext orgId> in root.tsx <head>
    • CSP directives → withSubtextCSP(...) in entry.server (replaces the manual directive edits)
    • commerce events + consent-gated capture → <SubtextAnalytics /> inside Analytics.Provider
    • Step 5 identity → useSubtextIdentity(customer && {...})
    • Step 6 analytics linkage (Sentry/GA4/PostHog/…) → onSessionUrl callback, which fires when capture actually starts (with consent gating that's well after page load, where a raw FS('getSession') call would return nothing)
    • user-facing caveats the agent must relay: no capture on *.oxygen preview URLs (privacy banner doesn't load), checkout is Shopify-hosted and out of scope

Why

A Hydrogen install today drops a ~20-line minified snippet into root.tsx and hand-edits the CSP (see the manual install in the hydrogen-storefront testbed). With the wrapper the diff is a few declarative lines, consent gating matches how Shopify gates its own analytics, and snippet updates ship as package versions instead of re-runs.

🤖 Generated with Claude Code


Note

Low Risk
Prompt and documentation only—no wizard runtime code—so behavior changes only affect how the install agent guides Hydrogen projects.

Overview
Hydrogen storefronts are now handled via the @subtextdev/hydrogen wrapper instead of pasting the raw inline capture snippet.

The install prompt treats @subtextdev/hydrogen in package.json as already installed, and checks @shopify/hydrogen first in framework detection so Remix/Vite deps do not win. A new Shopify Hydrogen framework block maps each install step to the wrapper: <Subtext> + nonce in root.tsx, withSubtextCSP in entry.server, <SubtextAnalytics> for commerce events and consent-gated capture, useSubtextIdentity and onSessionUrl for identity and analytics linkage, plus optional attachSessionToCart (with cart attribute handling and mode: 'ref' guidance) and user-facing notes on Oxygen preview URLs and checkout scope.

README NPM badge colors are updated; a patch changeset documents the wizard release.

Reviewed by Cursor Bugbot for commit 4deab29. Bugbot is set up for automated code reviews on this repo. Configure here.

nrodd and others added 2 commits July 30, 2026 12:10
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Hydrogen apps get the wrapper package instead of a pasted inline
snippet: <Subtext> (snippet + CSP nonce), withSubtextCSP in
entry.server, <SubtextAnalytics> (commerce events + consent-gated
capture + onSessionUrl linkage), and useSubtextIdentity. Detection
runs before the Remix/React Router/Vite checks so Hydrogen's own
dependencies can't shadow the match, and the pre-check treats
@subtextdev/hydrogen as already installed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ea63429. Configure here.

4. `app/entry.server.tsx` — wrap the existing directives object: `createContentSecurityPolicy(withSubtextCSP({...existing directives}))`, importing `withSubtextCSP` from `@subtextdev/hydrogen` (pass `{region: 'eu'}` as its second argument for EU orgs). This replaces the manual CSP directive edits from Step 2 — do not also add the directives by hand.
5. `app/root.tsx` — add `<SubtextAnalytics />` anywhere inside `<Analytics.Provider>`. It forwards Hydrogen's commerce events (`product_viewed`, `cart_updated`, search, collection, add/remove-to-cart) into capture and starts/stops capture as Customer Privacy consent changes.
6. For Step 5 (identity), use the package's `useSubtextIdentity(customer && {uid: customer.id, displayName, email})` hook where the authenticated customer is available on the client (typically the account route), instead of a raw `FS('setIdentity')` call.
7. For Step 6 (analytics linkage), pass `onSessionUrl` to `<SubtextAnalytics>` instead of calling `FS('getSession')` directly — it fires with the session URL every time capture starts, which with consent gating can be well after page load: `<SubtextAnalytics onSessionUrl={(url) => { /* attach subtext_url to each detected tool here */ }} />`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hydrogen overrides lost in later steps

Medium Severity

Hydrogen-specific identity and analytics guidance appears only as a brief note under Step 4, while Steps 5 and 6 still require raw FS('setIdentity') and FS('getSession') with no Hydrogen exception. Agents following those later steps can skip useSubtextIdentity and onSessionUrl, so consent-gated session URL linkage silently gets nothing.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ea63429. Configure here.

attachSessionToCart writes the session URL as a _-prefixed cart
attribute that Shopify carries onto the order (admin "Additional
details"), including the cart-action AttributesUpdateInput case the
agent must add and the mode:'ref' fallback for merchants who can't
vouch for their notification templates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant