-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(remix): Add support for Hydrogen #15450
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6b1e7b6
feat(remix): Add support for Hydrogen
onurtemizkan 6524a29
Reexport `browserTracingIntegration`
onurtemizkan 5c6dbdd
Remove `storefrontapi.generated.d.ts`
onurtemizkan dbecdb4
Add dummy `SESSION_SECRET` to CI for tests.
onurtemizkan 5209891
Include `.env` for Hydrogen-required dummy variables
onurtemizkan 264bc41
Try using `ubuntu-22.04` for e2e tests.
onurtemizkan f8ad74c
Avoid rebuilding on preview
onurtemizkan 3ec06c4
Merge branch 'develop' into onur/remix-hydrogen
onurtemizkan c6c7cec
Remove leftover comment.
onurtemizkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SESSION_SECRET = "foo" | ||
PUBLIC_STORE_DOMAIN="mock.shop" |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/remix-hydrogen/.eslintignore
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
node_modules | ||
bin | ||
*.d.ts | ||
dist |
79 changes: 79 additions & 0 deletions
79
dev-packages/e2e-tests/test-applications/remix-hydrogen/.eslintrc.cjs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* This is intended to be a basic starting point for linting in your app. | ||
* It relies on recommended configs out of the box for simplicity, but you can | ||
* and should modify this configuration to best suit your team's needs. | ||
*/ | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
env: { | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
}, | ||
|
||
// Base config | ||
extends: ['eslint:recommended'], | ||
|
||
overrides: [ | ||
// React | ||
{ | ||
files: ['**/*.{js,jsx,ts,tsx}'], | ||
plugins: ['react', 'jsx-a11y'], | ||
extends: [ | ||
'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:react-hooks/recommended', | ||
'plugin:jsx-a11y/recommended', | ||
], | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
formComponents: ['Form'], | ||
linkComponents: [ | ||
{ name: 'Link', linkAttribute: 'to' }, | ||
{ name: 'NavLink', linkAttribute: 'to' }, | ||
], | ||
'import/resolver': { | ||
typescript: {}, | ||
}, | ||
}, | ||
}, | ||
|
||
// Typescript | ||
{ | ||
files: ['**/*.{ts,tsx}'], | ||
plugins: ['@typescript-eslint', 'import'], | ||
parser: '@typescript-eslint/parser', | ||
settings: { | ||
'import/internal-regex': '^~/', | ||
'import/resolver': { | ||
node: { | ||
extensions: ['.ts', '.tsx'], | ||
}, | ||
typescript: { | ||
alwaysTryTypes: true, | ||
}, | ||
}, | ||
}, | ||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:import/recommended', 'plugin:import/typescript'], | ||
}, | ||
|
||
// Node | ||
{ | ||
files: ['.eslintrc.cjs', 'server.ts'], | ||
env: { | ||
node: true, | ||
}, | ||
}, | ||
], | ||
}; |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/remix-hydrogen/.gitignore
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
/.cache | ||
/build | ||
/dist | ||
/public/build | ||
/.mf | ||
!.env | ||
.shopify | ||
storefrontapi.generated.d.ts |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/remix-hydrogen/.npmrc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
37 changes: 37 additions & 0 deletions
37
dev-packages/e2e-tests/test-applications/remix-hydrogen/app/entry.client.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { RemixBrowser, useLocation, useMatches } from '@remix-run/react'; | ||
import * as Sentry from '@sentry/remix/cloudflare'; | ||
import { StrictMode, startTransition } from 'react'; | ||
import { useEffect } from 'react'; | ||
import { hydrateRoot } from 'react-dom/client'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
// Could not find a working way to set the DSN in the browser side from the environment variables | ||
dsn: 'https://[email protected]/1337', | ||
debug: true, | ||
integrations: [ | ||
Sentry.browserTracingIntegration({ | ||
useEffect, | ||
useLocation, | ||
useMatches, | ||
}), | ||
Sentry.replayIntegration({ | ||
maskAllText: true, | ||
blockAllMedia: true, | ||
}), | ||
], | ||
|
||
tracesSampleRate: 1.0, | ||
replaysSessionSampleRate: 0.1, | ||
replaysOnErrorSampleRate: 1.0, | ||
tunnel: 'http://localhost:3031/', // proxy server | ||
}); | ||
|
||
startTransition(() => { | ||
hydrateRoot( | ||
document, | ||
<StrictMode> | ||
<RemixBrowser /> | ||
</StrictMode>, | ||
); | ||
}); |
50 changes: 50 additions & 0 deletions
50
dev-packages/e2e-tests/test-applications/remix-hydrogen/app/entry.server.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { RemixServer } from '@remix-run/react'; | ||
import { createContentSecurityPolicy } from '@shopify/hydrogen'; | ||
import type { EntryContext } from '@shopify/remix-oxygen'; | ||
import isbot from 'isbot'; | ||
import { renderToReadableStream } from 'react-dom/server'; | ||
|
||
export default async function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext, | ||
) { | ||
const { nonce, header, NonceProvider } = createContentSecurityPolicy({ | ||
connectSrc: [ | ||
// Need to allow the proxy server to fetch the data | ||
'http://localhost:3031/', | ||
], | ||
}); | ||
|
||
const body = await renderToReadableStream( | ||
<NonceProvider> | ||
<RemixServer context={remixContext} url={request.url} /> | ||
</NonceProvider>, | ||
{ | ||
nonce, | ||
signal: request.signal, | ||
onError(error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
responseStatusCode = 500; | ||
}, | ||
}, | ||
); | ||
|
||
if (isbot(request.headers.get('user-agent'))) { | ||
await body.allReady; | ||
} | ||
|
||
responseHeaders.set('Content-Type', 'text/html'); | ||
responseHeaders.set('Content-Security-Policy', header); | ||
|
||
// Add the document policy header to enable JS profiling | ||
// This is required for Sentry's profiling integration | ||
responseHeaders.set('Document-Policy', 'js-profiling'); | ||
|
||
return new Response(body, { | ||
headers: responseHeaders, | ||
status: responseStatusCode, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
dev-packages/e2e-tests/test-applications/remix-hydrogen/app/functions/_middleware.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createPagesFunctionHandler } from '@remix-run/cloudflare-pages'; | ||
import { sentryPagesPlugin } from '@sentry/cloudflare'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore - the server build file is generated by `remix vite:build` | ||
// eslint-disable-next-line import/no-unresolved | ||
import * as build from '../build/server'; | ||
|
||
export const onRequest = [ | ||
context => sentryPagesPlugin({ dsn: context.env.E2E_TEST_DSN, tracesSampleRate: 1.0 })(context), | ||
createPagesFunctionHandler({ build }), | ||
]; |
174 changes: 174 additions & 0 deletions
174
dev-packages/e2e-tests/test-applications/remix-hydrogen/app/lib/fragments.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// NOTE: https://shopify.dev/docs/api/storefront/latest/queries/cart | ||
export const CART_QUERY_FRAGMENT = `#graphql | ||
fragment Money on MoneyV2 { | ||
currencyCode | ||
amount | ||
} | ||
fragment CartLine on CartLine { | ||
id | ||
quantity | ||
attributes { | ||
key | ||
value | ||
} | ||
cost { | ||
totalAmount { | ||
...Money | ||
} | ||
amountPerQuantity { | ||
...Money | ||
} | ||
compareAtAmountPerQuantity { | ||
...Money | ||
} | ||
} | ||
merchandise { | ||
... on ProductVariant { | ||
id | ||
availableForSale | ||
compareAtPrice { | ||
...Money | ||
} | ||
price { | ||
...Money | ||
} | ||
requiresShipping | ||
title | ||
image { | ||
id | ||
url | ||
altText | ||
width | ||
height | ||
|
||
} | ||
product { | ||
handle | ||
title | ||
id | ||
vendor | ||
} | ||
selectedOptions { | ||
name | ||
value | ||
} | ||
} | ||
} | ||
} | ||
fragment CartApiQuery on Cart { | ||
updatedAt | ||
id | ||
checkoutUrl | ||
totalQuantity | ||
buyerIdentity { | ||
countryCode | ||
customer { | ||
id | ||
firstName | ||
lastName | ||
displayName | ||
} | ||
phone | ||
} | ||
lines(first: $numCartLines) { | ||
nodes { | ||
...CartLine | ||
} | ||
} | ||
cost { | ||
subtotalAmount { | ||
...Money | ||
} | ||
totalAmount { | ||
...Money | ||
} | ||
totalDutyAmount { | ||
...Money | ||
} | ||
totalTaxAmount { | ||
...Money | ||
} | ||
} | ||
note | ||
attributes { | ||
key | ||
value | ||
} | ||
discountCodes { | ||
code | ||
applicable | ||
} | ||
} | ||
` as const; | ||
|
||
const MENU_FRAGMENT = `#graphql | ||
fragment MenuItem on MenuItem { | ||
id | ||
resourceId | ||
tags | ||
title | ||
type | ||
url | ||
} | ||
fragment ChildMenuItem on MenuItem { | ||
...MenuItem | ||
} | ||
fragment ParentMenuItem on MenuItem { | ||
...MenuItem | ||
items { | ||
...ChildMenuItem | ||
} | ||
} | ||
fragment Menu on Menu { | ||
id | ||
items { | ||
...ParentMenuItem | ||
} | ||
} | ||
` as const; | ||
|
||
export const HEADER_QUERY = `#graphql | ||
fragment Shop on Shop { | ||
id | ||
name | ||
description | ||
primaryDomain { | ||
url | ||
} | ||
brand { | ||
logo { | ||
image { | ||
url | ||
} | ||
} | ||
} | ||
} | ||
query Header( | ||
$country: CountryCode | ||
$headerMenuHandle: String! | ||
$language: LanguageCode | ||
) @inContext(language: $language, country: $country) { | ||
shop { | ||
...Shop | ||
} | ||
menu(handle: $headerMenuHandle) { | ||
...Menu | ||
} | ||
} | ||
${MENU_FRAGMENT} | ||
` as const; | ||
|
||
export const FOOTER_QUERY = `#graphql | ||
query Footer( | ||
$country: CountryCode | ||
$footerMenuHandle: String! | ||
$language: LanguageCode | ||
) @inContext(language: $language, country: $country) { | ||
menu(handle: $footerMenuHandle) { | ||
...Menu | ||
} | ||
} | ||
${MENU_FRAGMENT} | ||
` as const; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this: cloudflare/workerd#3411