-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remix-edge-adapter): use site entrypoint for Hydrogen sites
It appears to be (nearly?) imposssible to provide an out-of-the-box Netlify experience for Hydrogen sites that use Remix Vite. We may be able to solve for this at some point, but for now our only option is to expect these sites to contain a `server.ts` (or similar) file at the root. This is what Hydrogen templates do and what the Netlify Hydrogen template will do. There may be value in supporting this for Remix sites as well, but I haven't heard of a use case so I didn't bother supporting it here.
- Loading branch information
Showing
108 changed files
with
10,641 additions
and
5 deletions.
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
12 changes: 12 additions & 0 deletions
12
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/.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,12 @@ | ||
node_modules | ||
/.cache | ||
/build | ||
/dist | ||
/public/build | ||
/.mf | ||
.env | ||
.env.* | ||
.shopify | ||
|
||
# Local Netlify folder | ||
.netlify |
24 changes: 24 additions & 0 deletions
24
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/.graphqlrc.js
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,24 @@ | ||
import { getSchema } from '@shopify/hydrogen-codegen' | ||
|
||
/** | ||
* GraphQL Config | ||
* @see https://the-guild.dev/graphql/config/docs/user/usage | ||
* @type {IGraphQLConfig} | ||
*/ | ||
export default { | ||
projects: { | ||
default: { | ||
schema: getSchema('storefront'), | ||
documents: ['./*.{ts,tsx,js,jsx}', './app/**/*.{ts,tsx,js,jsx}', '!./app/graphql/**/*.{ts,tsx,js,jsx}'], | ||
}, | ||
|
||
customer: { | ||
schema: getSchema('customer-account'), | ||
documents: ['./app/graphql/customer-account/*.{ts,tsx,js,jsx}'], | ||
}, | ||
|
||
// Add your own GraphQL projects here for CMS, Shopify Admin API, etc. | ||
}, | ||
} | ||
|
||
/** @typedef {import('graphql-config').IGraphQLConfig} IGraphQLConfig */ |
52 changes: 52 additions & 0 deletions
52
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/README.md
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,52 @@ | ||
# Hydrogen template: Skeleton | ||
|
||
Hydrogen is Shopify’s stack for headless commerce. Hydrogen is designed to dovetail with [Remix](https://remix.run/), | ||
Shopify’s full stack web framework. This template contains a **minimal setup** of components, queries and tooling to get | ||
started with Hydrogen. | ||
|
||
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/hydrogen-template#SESSION_SECRET=mock%20token&PUBLIC_STORE_DOMAIN=mock.shop) | ||
|
||
- [Check out Hydrogen docs](https://shopify.dev/custom-storefronts/hydrogen) | ||
- [Get familiar with Remix](https://remix.run/docs/) | ||
|
||
## What's included | ||
|
||
- Remix 2 | ||
- Hydrogen | ||
- Shopify CLI | ||
- ESLint | ||
- Prettier | ||
- GraphQL generator | ||
- TypeScript and JavaScript flavors | ||
- Minimal setup of components and routes | ||
|
||
## Getting started | ||
|
||
**Requirements:** | ||
|
||
- Node.js version 18.0.0 or higher | ||
- Netlify CLI 17.0.0 or higher | ||
|
||
```bash | ||
npm install -g netlify-cli@latest | ||
``` | ||
|
||
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/hydrogen-template#SESSION_SECRET=mock%20token&PUBLIC_STORE_DOMAIN=mock.shop) | ||
|
||
To create a new project, either click the "Deploy to Netlify" button above, or run the following command: | ||
|
||
```bash | ||
npx create-remix@latest --template=netlify/hydrogen-template | ||
``` | ||
|
||
## Local development | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
## Building for production | ||
|
||
```bash | ||
npm run build | ||
``` |
28 changes: 28 additions & 0 deletions
28
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/app/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions
29
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/app/components/AddToCartButton.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,29 @@ | ||
import { type FetcherWithComponents } from '@remix-run/react' | ||
import { CartForm, type OptimisticCartLineInput } from '@shopify/hydrogen' | ||
|
||
export function AddToCartButton({ | ||
analytics, | ||
children, | ||
disabled, | ||
lines, | ||
onClick, | ||
}: { | ||
analytics?: unknown | ||
children: React.ReactNode | ||
disabled?: boolean | ||
lines: Array<OptimisticCartLineInput> | ||
onClick?: () => void | ||
}) { | ||
return ( | ||
<CartForm route="/cart" inputs={{ lines }} action={CartForm.ACTIONS.LinesAdd}> | ||
{(fetcher: FetcherWithComponents<any>) => ( | ||
<> | ||
<input name="analytics" type="hidden" value={JSON.stringify(analytics)} /> | ||
<button type="submit" onClick={onClick} disabled={disabled ?? fetcher.state !== 'idle'}> | ||
{children} | ||
</button> | ||
</> | ||
)} | ||
</CartForm> | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/e2e/fixtures/hydrogen-vite-site-no-entrypoint/app/components/Aside.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,72 @@ | ||
import { createContext, type ReactNode, useContext, useState } from 'react' | ||
|
||
type AsideType = 'search' | 'cart' | 'mobile' | 'closed' | ||
type AsideContextValue = { | ||
type: AsideType | ||
open: (mode: AsideType) => void | ||
close: () => void | ||
} | ||
|
||
/** | ||
* A side bar component with Overlay | ||
* @example | ||
* ```jsx | ||
* <Aside type="search" heading="SEARCH"> | ||
* <input type="search" /> | ||
* ... | ||
* </Aside> | ||
* ``` | ||
*/ | ||
export function Aside({ | ||
children, | ||
heading, | ||
type, | ||
}: { | ||
children?: React.ReactNode | ||
type: AsideType | ||
heading: React.ReactNode | ||
}) { | ||
const { type: activeType, close } = useAside() | ||
const expanded = type === activeType | ||
|
||
return ( | ||
<div aria-modal className={`overlay ${expanded ? 'expanded' : ''}`} role="dialog"> | ||
<button className="close-outside" onClick={close} /> | ||
<aside> | ||
<header> | ||
<h3>{heading}</h3> | ||
<button className="close reset" onClick={close}> | ||
× | ||
</button> | ||
</header> | ||
<main>{children}</main> | ||
</aside> | ||
</div> | ||
) | ||
} | ||
|
||
const AsideContext = createContext<AsideContextValue | null>(null) | ||
|
||
Aside.Provider = function AsideProvider({ children }: { children: ReactNode }) { | ||
const [type, setType] = useState<AsideType>('closed') | ||
|
||
return ( | ||
<AsideContext.Provider | ||
value={{ | ||
type, | ||
open: setType, | ||
close: () => setType('closed'), | ||
}} | ||
> | ||
{children} | ||
</AsideContext.Provider> | ||
) | ||
} | ||
|
||
export function useAside() { | ||
const aside = useContext(AsideContext) | ||
if (!aside) { | ||
throw new Error('useAside must be used within an AsideProvider') | ||
} | ||
return aside | ||
} |
Oops, something went wrong.