Add monorail analytics proxy as virtual resource route#3243
Closed
juanpprieto wants to merge 1 commit intomainfrom
Closed
Add monorail analytics proxy as virtual resource route#3243juanpprieto wants to merge 1 commit intomainfrom
juanpprieto wants to merge 1 commit intomainfrom
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
8e1eb7c to
2f451a6
Compare
Adds /.well-known/shopify/monorail/unstable/produce_batch as a virtual resource route to resolve runtime errors in Multipass setups where users navigate between Hydrogen and Shopify theme subdomains. Root Cause: - Shopify theme analytics scripts (trekkie.js, consent-tracking-api.js) persist after subdomain navigation - Scripts POST analytics to current domain (Hydrogen) - Hydrogen lacked the route Shopify themes provide - Result: 404 errors and "did not provide an action" React Router errors Solution: - Virtual resource route proxies to SHOPIFY_STORE_DOMAIN when configured - Returns raw responses (no layout wrapping) via React Router resource route pattern - Forwards all Shopify headers and status codes (200, 400, etc.) - Falls back to 204 No Content when domain not set - Preserves analytics data from theme subdomain visits Implementation: - Resource route (no default export) for raw responses - Uses response.body stream to avoid HTML serialization - 7 comprehensive unit tests (proxy, headers, fallback, errors) - All existing tests pass (445/445) SEO Fix: - Removed Disallow: /.well-known/shopify/monorail from robots.txt - Rationale: Shopify returns x-robots-tag: noindex header - Google best practice: Don't use both Disallow AND noindex - robots.txt blocking prevents crawlers from seeing noindex header - Let x-robots-tag header (forwarded from Shopify) prevent indexing - Reference: https://developers.google.com/search/docs/crawling-indexing/block-indexing Testing: - Unit: 7/7 passing - Integration: Validated on localhost and production (skylar.com investigation) - Confirmed: Proxies to hydrogen-preview.myshopify.com successfully Fixes runtime errors reported in: https://community.shopify.dev/t/hydrogen-errors/22604 Changes: - packages/hydrogen/src/vite/get-virtual-routes.ts - packages/hydrogen/src/vite/virtual-routes/routes/[.]well-known.shopify.monorail.unstable.produce_batch.tsx - packages/hydrogen/src/vite/virtual-routes/routes/[.]well-known.shopify.monorail.unstable.produce_batch.test.tsx - templates/skeleton/app/routes/[robots.txt].tsx
2f451a6 to
c6772e4
Compare
Contributor
|
This pull request has been marked as stale due to inactivity for 60 days. If no further activity occurs, it will be closed in 7 days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: https://github.com/Shopify/hydrogen-internal/issues/254
Summary
Adds
/.well-known/shopify/monorail/unstable/produce_batchas a virtual resource route that proxies Shopify analytics requests to the configured Shopify store domain, eliminating runtime errors in Multipass/Hybrid setups where users navigate between Hydrogen and Shopify theme subdomains.Why
Problem: In Multipass/Hybrid setups, Shopify theme analytics scripts persist after subdomain navigation and POST to the Hydrogen domain, causing runtime errors:
Affected setups: Any Hydrogen + Multipass configuration with subdomain redirects to Shopify themes (e.g., xyz.com)
Impact:
What
Implementation
Virtual Resource Route:
Implementation Details
Resource Route (no default export):
response.bodystream to preserve Shopify's exact responseRegistration:
Key Features
SHOPIFY_STORE_DOMAINenv varresponse.bodynotawait response.text()robots.txt SEO Fix
Removed:
Disallow: /.well-known/shopify/monorailRationale:
x-robots-tag: noindexheaderx-robots-tag: noindexheader prevent indexingReference: Google - Block Search Indexing with noindex
🎩 Top Hat
Prerequisites
SHOPIFY_STORE_DOMAINenvironment variable (optional)Testing Steps
Test 1: Verify Route Exists and Returns Raw Response
Test 2: Verify Proxy Functionality with Valid Payload
Test 3: Verify robots.txt Fix
Test 4: Run Unit Tests
Edge Cases to Test
SHOPIFY_STORE_DOMAIN(returns 204)SHOPIFY_STORE_DOMAINset (proxies correctly)Validation Checklist
npm test(445/445)npm run typecheck