Compare commits

...

163 Commits

Author SHA1 Message Date
Vercel Release Bot
bcebab7517 Version Packages (#10478)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/build-utils@7.2.0

### Minor Changes

- Add new optional prerender field: experimentalStreamingLambdaPath
([#10476](https://github.com/vercel/vercel/pull/10476))

- [build-utils] Add zero config detection for bun package manager
([#10486](https://github.com/vercel/vercel/pull/10486))

### Patch Changes

- add `experimentalBypassFor` field to Prerender
([#10481](https://github.com/vercel/vercel/pull/10481))

## vercel@32.2.1

### Patch Changes

- Update @vercel/fun@1.1.0
([#10477](https://github.com/vercel/vercel/pull/10477))

- [node] upgrade edge-runtime
([#10451](https://github.com/vercel/vercel/pull/10451))

- Updated dependencies
\[[`6784e7751`](6784e77516),
[`a8ad17626`](a8ad176262),
[`0ee089a50`](0ee089a501),
[`f15cba614`](f15cba6148),
[`b265e13d4`](b265e13d40),
[`50e04dd85`](50e04dd858),
[`45b73c7e8`](45b73c7e86),
[`a732d30c8`](a732d30c84),
[`9d64312aa`](9d64312aaa),
[`6baefc825`](6baefc825a),
[`989f0d813`](989f0d8139),
[`d8bc570f6`](d8bc570f60)]:
    -   @vercel/go@3.0.1
    -   @vercel/redwood@2.0.2
    -   @vercel/remix-builder@2.0.4
    -   @vercel/hydrogen@1.0.1
    -   @vercel/static-build@2.0.5
    -   @vercel/build-utils@7.2.0
    -   @vercel/next@4.0.3
    -   @vercel/node@3.0.5
    -   @vercel/python@4.0.1
    -   @vercel/ruby@2.0.2

## @vercel/client@13.0.3

### Patch Changes

- Updated dependencies
\[[`50e04dd85`](50e04dd858),
[`45b73c7e8`](45b73c7e86),
[`d8bc570f6`](d8bc570f60)]:
    -   @vercel/build-utils@7.2.0

## @vercel/edge@1.0.2

### Patch Changes

- [node] upgrade edge-runtime
([#10451](https://github.com/vercel/vercel/pull/10451))

## @vercel/gatsby-plugin-vercel-builder@2.0.5

### Patch Changes

- Updated dependencies
\[[`50e04dd85`](50e04dd858),
[`45b73c7e8`](45b73c7e86),
[`9d64312aa`](9d64312aaa),
[`d8bc570f6`](d8bc570f60)]:
    -   @vercel/build-utils@7.2.0
    -   @vercel/node@3.0.5

## @vercel/go@3.0.1

### Patch Changes

- Update to esbuild script
([#10468](https://github.com/vercel/vercel/pull/10468))

## @vercel/hydrogen@1.0.1

### Patch Changes

- Use `build-builder.mjs` script to bundle, and remove types and source
maps ([#10480](https://github.com/vercel/vercel/pull/10480))

## @vercel/next@4.0.3

### Patch Changes

- fix content-type for RSC prefetches
([#10487](https://github.com/vercel/vercel/pull/10487))

## @vercel/node@3.0.5

### Patch Changes

- [node] upgrade edge-runtime
([#10451](https://github.com/vercel/vercel/pull/10451))

- Updated dependencies
\[[`50e04dd85`](50e04dd858),
[`45b73c7e8`](45b73c7e86),
[`d8bc570f6`](d8bc570f60)]:
    -   @vercel/build-utils@7.2.0

## @vercel/python@4.0.1

### Patch Changes

- Update to esbuild script
([#10470](https://github.com/vercel/vercel/pull/10470))

## @vercel/redwood@2.0.2

### Patch Changes

- Update to esbuild script
([#10471](https://github.com/vercel/vercel/pull/10471))

## @vercel/remix-builder@2.0.4

### Patch Changes

- Use `build-builder.mjs` script to bundle, and remove types and source
maps ([#10479](https://github.com/vercel/vercel/pull/10479))

## @vercel/ruby@2.0.2

### Patch Changes

- Update to esbuild script
([#10472](https://github.com/vercel/vercel/pull/10472))

## @vercel/static-build@2.0.5

### Patch Changes

- Build package using "esbuild"
([#10462](https://github.com/vercel/vercel/pull/10462))

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@2.0.5

## @vercel-internals/types@1.0.10

### Patch Changes

- Updated dependencies
\[[`50e04dd85`](50e04dd858),
[`45b73c7e8`](45b73c7e86),
[`d8bc570f6`](d8bc570f60)]:
    -   @vercel/build-utils@7.2.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-11 17:30:02 -04:00
Steven
45b73c7e86 [build-utils] Add zero config detection for bun package manager (#10486)
> [!IMPORTANT]  
> This PR will only support Bun as a package manager at build time. 
> Bun will **not** work at runtime with Serverless Functions or Edge
Functions at this time.

- Depends on https://github.com/vercel/api/pull/21869
- Fixes https://github.com/orgs/vercel/discussions/2021
- Closes https://github.com/vercel/vercel/pull/10244
- Related https://github.com/nodejs/corepack/issues/295
- Docs https://bun.sh/docs/install
2023-09-11 17:26:34 -04:00
Zack Tanner
a732d30c84 [next] fix content-type for RSC prefetches (#10487)
This ensures that the `.prefetch.rsc` requests respond with the correct `content-type` since this is used by Next.js to determine if a request is valid or not (and in the case it's invalid, an mpa navigation will occur)

Fixes: https://github.com/vercel/next.js/issues/54934
2023-09-11 19:04:16 +00:00
Lee Robinson
8504735808 [examples] Update Astro starter (#10397)
Deployed https://astro.vercel.app/image.
2023-09-11 16:29:54 +00:00
Kiko Beats
9d64312aaa [node] upgrade edge-runtime (#10451) 2023-09-10 13:14:43 +00:00
Chris Barber
a8ad176262 [redwood] Use new esbuild script (#10471) 2023-09-09 01:48:54 +00:00
Nathan Rajlich
0ee089a501 [remix] Bundle, remove types and source maps (#10479)
For consistency with other Builders.
2023-09-09 00:35:56 +00:00
Zack Tanner
d8bc570f60 [build-utils] add experimentalBypassFor field to Prerender (#10481)
This adds an experimental flag to `Prerender` outputs as a way to programmatically bypass the cache and hit the lambda directly, using a similar interface to `has`. 

(Note: I copied over `HasField` from `@vercel/router-utils` since it wasn't available for import in `build-utils`, but can add it as a dep if that's preferred)

The specific use-case being targeted here relates to https://github.com/vercel/next.js/pull/51534 -- a Next.js page marked static should still be able to initiate server actions.
2023-09-08 23:33:59 +00:00
Nathan Rajlich
f15cba6148 [hydrogen] Bundle, remove types and source maps (#10480)
Similar to #10479, but for `@vercel/hydrogen`.
2023-09-08 22:55:03 +00:00
Chris Barber
989f0d8139 [ruby] Use new esbuild script (#10472) 2023-09-08 17:27:17 -05:00
Chris Barber
6784e77516 [go] Update to esbuild script (#10468)
Co-authored-by: Nathan Rajlich <n@n8.io>
2023-09-08 17:00:40 -05:00
Chris Barber
6baefc825a [python] Update to esbuild script (#10470)
Co-authored-by: Steven <steven@ceriously.com>
2023-09-08 16:23:23 -05:00
Chris Barber
0a08e4b23e [cli] Update @vercel/fun@1.1.0 (#10477) 2023-09-08 15:39:13 -05:00
Nathan Rajlich
b265e13d40 [static-build] Use esbuild (#10462)
Switch to using esbuild to compile + bundle `@vercel/static-build`.
2023-09-08 19:39:12 +00:00
Nabeel Sulieman
50e04dd858 Add optional experimentalStreamingLambda field for prerender (#10476)
This adds a new `experimentalStreamingLambda` field to Prerender
outputs, allowing references to an optional streaming lambda path.
2023-09-08 11:42:06 -07:00
Vercel Release Bot
82231058da Version Packages (#10400)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-08 11:41:32 -05:00
Steven
61227bf7e3 fix .changeset/nice-lies-sip.md (#10474)
I think we need to remove `api` since its private so its not published to npm and therefore isn't versioned.
2023-09-08 02:09:11 +00:00
Zack Tanner
6aa0aa4e65 [next] fix ENOENT on /404.html when fallback: false w/ basePath (#10473)
The following error occurs during build when `basePath` is present in conjunction with `fallback: false` in `getStaticPaths`:

> Error: ENOENT: no such file or directory, open '/vercel/path0/.next/server/pages/404.html'

`localePrefixed404` was incorrectly being set to `false` because it was looking for `/<basePath>/<locale>/404.html` (when it's actually `/<locale>/404.html`)

This meant that inside `onPrerenderRoute`, `htmlFsRef` was pointing to `/404.html` rather than `/en/404.html`.
2023-09-08 00:17:08 +00:00
JJ Kasper
caaba0d685 [next] fix app dir edge functions with basePath (#10465)
x-ref: https://github.com/vercel/vercel/pull/10394
2023-09-07 22:03:12 +00:00
Steven
335fd70a68 [ci] Update codeowners (#10467)
Update codeowners for Next.js
2023-09-07 14:20:20 +00:00
Zack Tanner
c3c54d6e69 [next]: Fix RSC rewrite behavior (#10415)
- Removes some of the hacks from #10388 that were attempting to resolve an issue with RSC prefetches to `pages` routes in favor of adding rsc rewrites for all dynamic paths, and letting it fall through to a 404 if there's no match
- Fixes an issue where RSC requests were matching the wrong path (filesystem rather than RSC variant) introduced in above mentioned change
  - Closes https://github.com/vercel/next.js/issues/54698
2023-09-07 14:03:14 +00:00
Shu Uesugi
43048a0dd8 [CLI] Fix team URL on vercel help switch (#10466)
In `vercel help switch`, it suggests that team URL is of the format `vercel.com/teams/name`, but this will be 404. It should be `vercel.com/name`.
2023-09-07 13:12:54 +00:00
Sean Massa
60c75fd76c [CLI] show instant preview url on vc deploy and vc redeploy (#10458)
Show Instant Preview URLs immediately during `vc deploy`.

This does mean that we'll no longer show the nicer aliased URLs, but that's probably fine.

https://github.com/vercel/vercel/assets/41545/5d6d5695-60c3-49ca-a54d-a16828583070

---

- [Card](https://linear.app/vercel/issue/VCCLI-897/show-instant-preview-url-on-vc-deploy)
2023-09-06 23:46:44 +00:00
Trek Glowacki
bd1319d7a3 [cli] Update secrets.js to more current styles (#10461)
Updates the `secrets` command to be a bit more modern. Initially I was going to covert this to typescript but that change was quite large, so going stepwise for easier review.

1. Moves the command implementation into a directory like other commands
2. Shifts the command data structure into its own file
3. Adds a test.

Other relevant comments inline.
2023-09-06 20:58:57 +00:00
Nathan Rajlich
1138f7e3d1 Use esbuild for non-ncc'd packages (#10430)
The intention is for this to be a drop-in replacement for compiling TypeScript to JavaScript, but using `esbuild` instead of `tsc`. `tsc` is still needed, but only for the cases where we want to generate type definitions.
2023-09-06 19:49:50 +00:00
Ethan Arrowood
bb95cb9225 [cli] migrate teams command (#10434)
Before:
<img width="661" alt="Screenshot 2023-08-31 at 13 59 35" src="https://github.com/vercel/vercel/assets/16144158/7d16367a-662e-4ef1-8561-c197f4badf48">

After:
<img width="1036" alt="Screenshot 2023-08-31 at 14 00 23" src="https://github.com/vercel/vercel/assets/16144158/64431bdb-48ce-4bc1-8ed0-c719bdfbb350">
2023-09-06 16:15:35 +00:00
Trek Glowacki
0048eb999e [cli] N, not n. (#10460)
Followup to https://github.com/vercel/vercel/pull/10432#discussion_r1315482954
2023-09-06 15:42:37 +00:00
Espen Hovlandsdal
1b4de4a986 chore(deps): upgrade semver dependency (#10411)
Addresses ReDoS vulnerability: https://security.snyk.io/vuln/SNYK-JS-SEMVER-3247795
Uses the latest unaffected versions in the respective major versions, to prevent having to deal with any other breaking changes.
2023-09-06 13:37:37 +00:00
JJ Kasper
c9ad4084ee [next] Update page config test (#10456)
Updates failing test in https://github.com/vercel/vercel/actions/runs/6090040294/job/16525842631?pr=10430 per changes in https://github.com/vercel/next.js/pull/54786
2023-09-06 00:46:37 +00:00
Trek Glowacki
98ee6e4728 [cli] Migrate domains to new command structure (#10427)
After:
<img width="790" alt="CleanShot 2023-08-31 at 11 39 25@2x" src="https://github.com/vercel/vercel/assets/9736/b2e0e090-8c7c-4659-b1aa-1c59744d2eb1">

Before:
<img width="813" alt="CleanShot 2023-08-31 at 11 40 06@2x" src="https://github.com/vercel/vercel/assets/9736/731626a0-86f0-446d-8f77-436205acac87">
2023-09-05 21:11:03 +00:00
Vercel Release Bot
d7db0c5794 [tests] Upgrade Turbo to version 1.10.13 (#10404)
This auto-generated PR updates Turbo to version 1.10.13
2023-09-05 20:28:17 +00:00
Sean Massa
e90e922ee8 migrate dev command structure for help output (#10433)
Migrates the `vc git` command to the command data structure for use in the help output.

---

<img width="1891" alt="Screenshot 2023-08-31 at 1 35 07 PM" src="https://github.com/vercel/vercel/assets/41545/d3d63faa-9427-49e8-8137-a76d4c208cb3">
2023-09-05 19:51:44 +00:00
Trek Glowacki
adb9ac87ce [cli] Remove mri workaround (#10452)
As of https://github.com/vercel/vercel/pull/10389 the `mri` package is no longer used and this workaround can be removed.
2023-09-05 16:17:18 +00:00
Steven
e43191b186 [next] fix 404 enoent for i18n (#10416)
This PR fixes the following error:

```
Error: ENOENT: no such file or directory, open '/vercel/path0/.next/server/pages/en/404.html'
```


https://github.com/vercel/vercel/actions/runs/6030773334/job/16364078054?pr=10415#step:9:1352
2023-09-01 10:39:52 -04:00
Dan Stowell
a962e84409 migrate env to command structure (#10429)
Migrates the `vc env` command to the command data structure for use in the help output.
2023-08-31 23:10:28 +00:00
Trek Glowacki
7593e219fd [cli] Update project command to new structure (#10432)
Before:
<img width="687" alt="CleanShot 2023-08-31 at 13 29 29@2x" src="https://github.com/vercel/vercel/assets/9736/87e0f445-701a-4851-b73f-c787db01abe3">

After:
<img width="868" alt="CleanShot 2023-08-31 at 13 31 50@2x" src="https://github.com/vercel/vercel/assets/9736/b6820654-3254-4a65-820a-30ff7b577a44">
2023-08-31 22:45:44 +00:00
Dan Stowell
ec95066689 migrate vc secrets to help command structure (#10435) 2023-08-31 15:17:51 -07:00
Sean Massa
42a71416b9 migrate init command structure for help output (#10428)
Migrates the `vc init` command to the command data structure for use in the help output.

---

<img width="1891" alt="Screenshot 2023-08-31 at 11 36 37 AM" src="https://github.com/vercel/vercel/assets/41545/1caeb203-470f-49a5-86b2-273b04bc0489">
2023-08-31 21:48:09 +00:00
Sean Massa
80af30ce60 migrate git command structure for help output (#10431) 2023-08-31 16:02:49 -05:00
Sean Massa
74a15b5f32 migrate rollback command structure for help output (#10426)
Migrates the `vc rollback` command to the command data structure for use in the help output.

---

<img width="1891" alt="Screenshot 2023-08-31 at 11 25 49 AM" src="https://github.com/vercel/vercel/assets/41545/a6d802ac-3851-4641-b950-764fc65fa9d2">
2023-08-31 19:09:59 +00:00
Sean Massa
c0416f7e95 migrate promote command structure for help output (#10425)
Migrates the `vc promote` command to the command data structure for use in the help output.

---

<img width="1878" alt="Screenshot 2023-08-31 at 11 04 32 AM" src="https://github.com/vercel/vercel/assets/41545/b79c6aec-af03-4685-8ee4-9c0d89b2f236">
2023-08-31 18:41:55 +00:00
Kiko Beats
fc1e13c099 fix: remove console.log (#10417) 2023-08-31 16:34:27 +02:00
Nathan Rajlich
0e9ec194a3 Keep vercel@canary up to date with vercel@latest (#10410) 2023-08-28 22:50:30 -07:00
Sean Massa
5609a1187b [build-utils] add descriptions to NodeVersion properties (#10403) 2023-08-26 19:49:47 -05:00
Sean Massa
cff72e3129 [examples] fix redwood template and update examples to use at least node@16 (#10395)
The redwood template was broken because it would use node@18, which is not supported for the version of redwood used in the template. This PR updates that version to be node@16, which does work.

While we're at it, I also updated other examples to be at least node@16. I tested deployments of each of these and the all work.
2023-08-25 15:01:55 +00:00
Vercel Release Bot
d3c84e5d2a Version Packages (#10398)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-24 16:04:39 -05:00
Andrew Barba
9e3827c785 [build-utils] Support serverless function architecture (#10392)
# Problem

Framework authors often produce build outputs from platforms like Github
Actions or M1 Macs where the arm64 architecture is being used. They then
deploy these outputs to Vercel using `vercel deploy`, bypassing Vercel's
build system. Today they must cross compile to x86_64 in order to deploy
compatible Serverless functions to Vercel.

# Solution

Allow Framework authors to detect the current architecture and specify
either x86_64 or arm64 when deploying a Serverless function to Vercel.

# Related PRs

https://github.com/vercel/api/pull/21559

https://github.com/vercel/proxy/pull/6901

https://github.com/vercel/front/pull/24924
2023-08-24 16:44:30 -04:00
Trek Glowacki
fb6d77afac [cli] Improve error messages for JSON parse issues (#10396) 2023-08-24 15:09:13 -05:00
Vercel Release Bot
cfc1bb180b Version Packages (#10384)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-24 13:56:29 -05:00
Trek Glowacki
f06776468f [cli] Remove mri package (#10389)
`vc secrets` appears to be mostly deprecated but this was a fairly straightforward change that lets us drop `mri` today. Tested pretty extensively locally.
2023-08-24 18:05:11 +00:00
Kiko Beats
597a8a8176 upgrade edge-runtime (#10385) 2023-08-24 16:52:49 +02:00
Kiko Beats
3f6d99470d [node] use undici instead of node-fetch (#10387) 2023-08-24 10:06:33 +02:00
JJ Kasper
4422326865 Add handling to leverage RSC prefetch outputs (#10390)
Implements handling for the RSC prefetch outputs when available that
were added in https://github.com/vercel/next.js/pull/54403
2023-08-23 22:26:58 -07:00
Zack Tanner
09446a8fe8 [next] fix RSC matching behavior & 404 status code on fallback: false (#10388)
Fixes two separate issues for the Next builder:

- `pages` routes unexpectedly matching to RSC routes when prefetching from `app`. This update will attempt to match the route with the corresponding `pages` entry rather than falling back to a catch-all RSC
  - Fixes https://github.com/vercel/next.js/issues/53776
- `fallback: false` returning a successful status code when underlying page as a param (e.g. `/blog/[slug]` would 200 but `/blog/non-existent` would 404)
  - [slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1692817762403579)
2023-08-23 22:30:33 +00:00
Vercel Release Bot
37e93a91a8 [remix] Update @remix-run/dev to v1.19.3 (#10381)
This auto-generated PR updates `@remix-run/dev` to version 1.19.3.
2023-08-22 20:49:48 +00:00
Trek Glowacki
eec6e47232 [cli] Update dns commands to new structure (#10379)
Before:
<img width="795" alt="CleanShot 2023-08-22 at 10 46 34@2x" src="https://github.com/vercel/vercel/assets/9736/456faef8-6335-46ac-89ae-5ce13db4568e">


After:
<img width="815" alt="CleanShot 2023-08-22 at 10 48 04@2x" src="https://github.com/vercel/vercel/assets/9736/e78a9cc5-d9e9-4079-bd4a-81cd68917127">
2023-08-22 20:24:19 +00:00
Vercel Release Bot
3a0cfce669 Version Packages (#10375)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-22 14:43:00 -05:00
Maz
ae4a9535c1 [cli] Add --git-branch to pull command help output (#10382)
Improves the help for pull command by adding --git-branch to the output.
2023-08-22 12:27:29 -07:00
Sean Massa
c615423a0b [frameworks] move some devDependencies to dependencies (#10380)
Because `frameworks` isn't bundled with `ncc`, we need the runtime dependencies to exist in the `dependencies` section of `package.json`.
2023-08-22 17:31:19 +00:00
Steven
96f99c7147 [error-utils] fix files in package.json to use dist (#10378)
These packages were publishing unnecessary files to npm so we can reduce to only the `dist` directory.

- Example: https://unpkg.com/browse/@vercel/error-utils@2.0.0/
- Docs: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#files
2023-08-22 17:04:57 +00:00
Trek Glowacki
8f318d44cb Migrate certs to new command structure (#10377)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
2023-08-22 10:33:36 -05:00
Vercel Release Bot
ade5e4ea0a [examples][tests] Upgrade Next.js to version 13.4.19 (#10373)
This auto-generated PR updates 3 packages to Next.js version 13.4.19
2023-08-21 23:55:07 +00:00
Trek Glowacki
87dee36ef9 [cli] Update new --help structure to support subcommands (#10372)
Before:
<img width="727" alt="CleanShot 2023-08-21 at 11 07 25@2x" src="https://github.com/vercel/vercel/assets/9736/1ff4b5b8-75e3-4fcb-b44a-7172e7612ecc">

After:
<img width="759" alt="CleanShot 2023-08-21 at 11 13 21@2x" src="https://github.com/vercel/vercel/assets/9736/acdd954a-6137-4535-8fbb-db025491156b">

Some notes re: "Before"

* We've dropped wrapping required args in `<>` some time ago.
* The command name for alias is optional (default is `set`) but was incorrectly still listed as required.
2023-08-21 21:31:02 +00:00
Vercel Release Bot
c97407da49 Version Packages (#10361)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-21 15:10:45 -05:00
Steven
37f5c62700 BREAKING CHANGE: Drop Node.js 14, bump minimum to Node.js 16 (#10369)
https://vercel.com/changelog/node-js-14-and-16-are-being-deprecated


https://github.com/nodejs/Release/blob/main/README.md#end-of-life-releases
2023-08-21 08:51:38 -04:00
Trek Glowacki
104ab0332d [cli] Wrap description in help output (#10370)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
2023-08-18 15:01:45 -05:00
Vercel Release Bot
8ed71bea65 [examples][tests] Upgrade Next.js to version 13.4.18 (#10366)
This auto-generated PR updates 3 packages to Next.js version 13.4.18
2023-08-18 13:36:13 -04:00
Chris Barber
bc7a5d38be Exclude Gatsby from default 404 error route (#10365)
All static builds (except Next.js) have a default 404 error route. This PR add the exclusion of Gatsby from being assigned a 404 error route. The error routes are now introduced by the `gatsby-plugin-vercel-builder`.

Linear: https://linear.app/vercel/issue/VCCLI-749/fix-gatsby-404500-pages-directory-listing-bug
2023-08-18 17:10:40 +00:00
Nathan Rajlich
09174df6cf [remix] Only add workspace check flag for Yarn v1 (#10364)
Yarn v2/v3 do not require this flag.
2023-08-17 19:17:28 +00:00
Trek Glowacki
6aa2dc6f51 Connecting Datadog / GH Actions / Turbo / Jest to detect flakey tests (#10334)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
Co-authored-by: Steven <steven@ceriously.com>
2023-08-17 10:31:16 -05:00
Vercel Release Bot
9db3794735 [examples][tests] Upgrade Next.js to version 13.4.17 (#10362)
This auto-generated PR updates 3 packages to Next.js version 13.4.17
2023-08-17 10:09:28 -04:00
Nathan Rajlich
ed806d8a6b [frameworks][fs-detectors] Add "supersedes" prop to Framework interface (#10345)
The `supersedes` property on the `Framework` interface may be specified by a framework in which the superseded framework should _not_ be included in the resulting framework matches during detection.

For example, a Hydrogen v2 project matches both the "remix" and "hydrogen" framework detectors, but we really only want "remix" to be selected.
2023-08-17 07:30:32 +00:00
Vercel Release Bot
de9a1dbab7 Version Packages (#10359)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@31.4.0

### Minor Changes

- Force-publish ([#10358](https://github.com/vercel/vercel/pull/10358))

### Patch Changes

- Updated dependencies
\[[`6e44757ff`](6e44757ff5)]:
    -   @vercel/static-build@1.4.0

## @vercel/static-build@1.4.0

### Minor Changes

- Force-publish ([#10358](https://github.com/vercel/vercel/pull/10358))
2023-08-16 20:34:05 -07:00
Nathan Rajlich
ae9b33b801 Force-publish on @vercel/static-build 2023-08-16 20:12:12 -07:00
Chris Barber
6e44757ff5 v31.4.0 (#10358)
https://github.com/vercel/vercel/pull/10356 didn't publish a new CLI release, so this PR should do the trick.
2023-08-16 23:19:43 +00:00
Vercel Release Bot
8dcefe5e83 Version Packages (#10356)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-16 18:02:42 -05:00
Riz
65ab3b23e9 [frameworks] Amend Hugo default buildCommand to exclude drafts enabled flag (#7326)
### Related Issues

Reported in https://github.com/vercel/community/discussions/194

Having the `-D` flag results in all draft content to be published (docs reference [here](https://gohugo.io/getting-started/usage/)).

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
2023-08-16 21:29:09 +00:00
Nathan Rajlich
8f152a5939 [build-utils] Fix Node 14.x tests (#10355) 2023-08-16 20:59:14 +00:00
Nathan Rajlich
10a6aa55f9 [tests] Fix failures due to Node 14.x being discontinued (#10346)
This PR upgrades test fixtures from Node.js 14 to 16 and also removes
the `35-puppeteer` test fixture since it doesn't support Node.js 16
unfortunately.

- See https://github.com/alixaxel/chrome-aws-lambda/pull/274

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-08-15 17:59:21 -04:00
Vercel Release Bot
936a428420 [examples][tests] Upgrade Next.js to version 13.4.16 (#10344)
This auto-generated PR updates 3 packages to Next.js version 13.4.16

Closes #10339
2023-08-15 15:21:06 +00:00
Steven
a93e1a7a64 [examples] update ember example (#10347)
This PR updates the ember example using the following:

```
npx ember new ember-quickstart --lang en
```

I also had to add `{ 'ember-welcome-page': { enabled: true } }` to the
build config because the `<WelcomePage>` only works in dev, but throws
when using the default build command:

```
ember build --environment=production
```

For posterity, the error looks like:
```
Uncaught TypeError: Cannot destructure property 'manager' of 'e' as it is null.
    at u.resolvedComponent (vendor-2e12520b7a71eead28708a24fafa7fbc.js:2094:28)
    at vendor-2e12520b7a71eead28708a24fafa7fbc.js:1999:5
    at ne (vendor-2e12520b7a71eead28708a24fafa7fbc.js:1999:30)
    at l (vendor-2e12520b7a71eead28708a24fafa7fbc.js:1991:18)
    at vendor-2e12520b7a71eead28708a24fafa7fbc.js:1981:836
    at _.compile (vendor-2e12520b7a71eead28708a24fafa7fbc.js:1938:173)
    at re (vendor-2e12520b7a71eead28708a24fafa7fbc.js:1991:61)
    at vendor-2e12520b7a71eead28708a24fafa7fbc.js:1988:30
    at ee.compile (vendor-2e12520b7a71eead28708a24fafa7fbc.js:1989:23)
    at Object.evaluate (vendor-2e12520b7a71eead28708a24fafa7fbc.js:2431:224)
```

- Related https://github.com/emberjs/ember.js/issues/19912
- Related https://github.com/ember-cli/ember-welcome-page/issues/385
2023-08-15 11:05:31 -04:00
Trek Glowacki
4ba188ce44 [cli] fix tyops (#10338)
Followup to #10333
2023-08-15 07:33:24 +00:00
Vercel Release Bot
7682c9234c Version Packages (#10343)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@31.3.1

### Patch Changes

- Updated dependencies
\[[`844fb6e88`](844fb6e880)]:
    -   @vercel/remix-builder@1.10.1

## @vercel/remix-builder@1.10.1

### Patch Changes

- Set default env vars for Hydrogen v2 deployments
([#10341](https://github.com/vercel/vercel/pull/10341))

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-14 18:13:53 -07:00
Nathan Rajlich
844fb6e880 [remix] Set default env vars for Hydrogen v2 deployments (#10341)
In order to make the default mock shop created from `npm create @shopify/hydrogen@latest` work out-of-the-box and without additional configuration, set the necessary default environment variables to make the server not render an error.
2023-08-15 01:11:01 +00:00
Nathan Rajlich
ae20c7230f [cli] Use vercel-php@0.6.0 in e2e test fixture (#10342)
`0.5.2` uses Node 14, so this test was failing.

<img width="934" alt="Screenshot 2023-08-14 at 5 13 31 PM"
src="https://github.com/vercel/vercel/assets/71256/654c8f71-6006-4b98-9ef0-fe288651d158">
2023-08-14 17:50:52 -07:00
Nathan Rajlich
a36b8eb738 [examples] Update "hydrogen-2" template readme (#10340)
A few tweaks to the readme file for `hydrogen-2`, based on feedback from
Shopify.
2023-08-14 16:05:12 -07:00
Vercel Release Bot
78be5aedd5 Version Packages (#10318)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@31.3.0

### Minor Changes

- Update help output to use cli-table3
([#10333](https://github.com/vercel/vercel/pull/10333))

### Patch Changes

- Sanitize argv in log during `vc build`.
([#10311](https://github.com/vercel/vercel/pull/10311))

- Respect `--yes` flag for all prompts during `vc link --repo`
([#10337](https://github.com/vercel/vercel/pull/10337))

- Updated dependencies
\[[`8cb9385fd`](8cb9385fd3),
[`94c93dfb5`](94c93dfb5b)]:
    -   @vercel/node@2.15.10
    -   @vercel/static-build@1.3.46

## @vercel/frameworks@1.5.1

### Patch Changes

- Add "(v1)" suffix to "hydrogen" preset
([#10320](https://github.com/vercel/vercel/pull/10320))

- Use parenthesis on Docusaurus "name" fields
([#10324](https://github.com/vercel/vercel/pull/10324))

## @vercel/fs-detectors@4.1.2

### Patch Changes

- Updated dependencies
\[[`33d9c1b7f`](33d9c1b7f9),
[`f54598724`](f54598724c)]:
    -   @vercel/frameworks@1.5.1

## @vercel/gatsby-plugin-vercel-builder@1.3.18

### Patch Changes

- Updated dependencies
\[[`8cb9385fd`](8cb9385fd3),
[`94c93dfb5`](94c93dfb5b)]:
    -   @vercel/node@2.15.10

## @vercel/node@2.15.10

### Patch Changes

- Update 'edge-runtime' to 2.4.4
([#10255](https://github.com/vercel/vercel/pull/10255))

- `edge-light` condition interoperability with `vercel dev`
([#10313](https://github.com/vercel/vercel/pull/10313))

## @vercel/static-build@1.3.46

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@1.3.18

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-14 13:00:01 -06:00
Nathan Rajlich
a1c3bfb50f [cli] Respect --yes flag for all prompts during vc link --repo (#10337)
A couple of the prompts during `vc link --repo` were not honoring the `--yes` flag.
2023-08-14 18:26:45 +00:00
Trek Glowacki
78fa02292d [cli] Swap custom table code with cli-table3 (#10333)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
2023-08-14 10:12:43 -05:00
Vladislav Ponomarev
94c93dfb5b edge-light condition interoperability with vercel dev (#10313)
Co-authored-by: Chris Barber <chris.barber@vercel.com>
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-08-11 13:08:34 -05:00
Trek Glowacki
19addabb6e [cli] Add tests to demonstrate function detection precedence (#10331)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
2023-08-11 11:18:13 -05:00
Lee Robinson
45fc0dd714 [examples] Update Storybook template (#10063)
To use stable App Router.

New deployment: https://storybook-template.vercel.app/
2023-08-11 00:09:02 +00:00
Nathan Rajlich
fc524a1e6a Fixes for changeset from #10255 (#10328) 2023-08-10 16:49:05 -07:00
Hassan Bazzi
8cb9385fd3 [node] bump edge-runtime to 2.4.4 (#10255)
# Summary

Edge-runtime 2.4.4 has many bug fixes, but most importantly it adds support for stream cancellation to the edge runtime. This is extremely important since a lot of projects are using `streams` related to `ai`. They currently have no way of handling a cancellation coming from the client.

This was introduced to `next` with as described by this comment: https://github.com/vercel-labs/ai/issues/90#issuecomment-1618915409

You can find the PR for that here: https://github.com/vercel/next.js/pull/51727

It also has a good description for what we're trying to do here, but for people not using `next`

# Problem

When a client sends an abort signal, it is currently not being handled by edge functions. This was fixed in edge-runtime@2.4.4

# Solution

Update the package
2023-08-10 23:39:35 +00:00
Nathan Rajlich
f54598724c [frameworks] Use parenthesis on Docusaurus and SvelteKit "name" fields (#10324)
For consistency with https://github.com/vercel/vercel/pull/10320.
2023-08-10 22:41:00 +00:00
Nathan Rajlich
abd1197c90 [fs-detectors] Fix "hydrogen-2" detection unit test (#10325)
Follow-up to https://github.com/vercel/vercel/pull/10319, which didn't exhibit this failing test since the fs-detectors package was not changed, and thus those tests didn't run.
2023-08-10 21:25:51 +00:00
Trek Glowacki
db27f409b6 [cli] tidy up use of package name and logo (#10323)
I erred on the side of preferring the more recently added versions of this behavior. I assume at some point in the distant past the removed function correctly toggled between some now/zeit/vercel transitioning.
2023-08-10 18:04:24 +00:00
Nathan Rajlich
33d9c1b7f9 [frameworks] Add "(v1)" suffix to "hydrogen" preset (#10320)
Now that the "remix" preset should be used for Hydrogen v2, it's not very clear that the "hydrogen" preset is only meant to be used for Hydrogen v1.

So add clarification in the "name" of the "hydrogen" preset to help remedy that.
2023-08-10 02:32:57 +00:00
Nathan Rajlich
97659c687b [examples] Add "hydrogen-2" template (#10319)
Adds a Hydrogen v2 template which is the output of the `npm create @shopify/hydrogen@latest` command.

Note that a `vercel.json` file is being used to define the environment variables that are required at runtime. This is required for the template to deploy with zero configuration, however the user should update these values (including replacing the session secret) and migrate them to the Project settings in the Vercel dashboard.

[Live example](https://hydrogen-v2-template.vercel.app)
2023-08-10 00:11:33 +00:00
Chris Barber
d6f18f4e2d [cli] Sanitize argv for vc build (#10311)
`vc build` writes a file `.vercel/output/build.json` that contains the `argv` contents which could include sensitive information that needs to be sanitized.
2023-08-09 15:01:18 +00:00
Vercel Release Bot
f43e413ba5 Version Packages (#10302)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-08 17:10:58 -05:00
Nathan Rajlich
0945d24cbe [remix] Add initial support for Hydrogen v2 (#10305)
Enables support for Hydrogen v2 apps using the "Remix" preset. This initial support works with the Hydrogen demo store template unmodified, and all pages will use Edge functions.

Node.js runtime, and also any other configuration via `export const config`, are not supported at this time, due to some pending blockers.
2023-08-08 21:39:57 +00:00
Steven
a8ecf40d6f [build-utils] Fix getPrefixedEnvVars() to handle VERCEL_BRANCH_URL (#10315)
- Fixes [NEXT-1500](https://linear.app/vercel/issue/NEXT-1500)
- See
[documentation](https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables#framework-environment-variables)
2023-08-08 14:43:20 -04:00
Steven
2995781a58 Revert "Just testing changeset stuff"
This reverts commit e2096c268d.
2023-08-07 16:36:40 -04:00
Trek Glowacki
e2096c268d Just testing changeset stuff 2023-08-07 15:33:26 -05:00
Amy
663d8e6437 Update discussion templates (#10297)
The current note on discussion templates is not bold enough and easily overlooked.

In an effort to reduce off-topic discussion clutter in this repo and direct folks to the general support community which I monitor more closely, this update makes the note more prominent.
2023-08-07 18:33:41 +00:00
Trek Glowacki
153ca440fa Add basic tests for remove command (#10304)
Adds some minimal unit testing for the `remove` command. There is currently none.
2023-08-07 18:14:21 +00:00
Steven
c5e0cb4812 chore(ci): fix turbo logs to no longer group (#10310)
When we upgraded `turbo`, the default `--log-order` changed from `stream` to `grouped`.

This PR changes it back to `stream` which will prevent the collapsed group view that we currently see in CI.

https://turbo.build/repo/docs/reference/command-line-reference/run#--log-order

> If log order is set to auto and turbo detects that it is running on GitHub Actions, then turbo will create grouped logs(opens in a new tab). You can opt out of this behavior by setting a log order of your own.
2023-08-07 16:44:41 +00:00
Seiya Nuta
5bf1fe4c74 [next] Preserve sourceMappingURL comments in template literals (#10275)
We noticed some edge function builds are failing unexpectedly due to `SyntaxError`. It's triggered by valid code in [Webpack's style-loader](16e401b17a/src/runtime/styleDomAPI.js (L35C1-L40C1)):

```
  if (sourceMap && typeof btoa !== "undefined") {
    css += `\n/*# sourceMappingURL=data:application/json;base64,${btoa(
      unescape(encodeURIComponent(JSON.stringify(sourceMap)))
    )} */`;
  }
```

After minification this script looks like:

```
sourceMap&&typeof btoa!="undefined"&&(css+=`
/*# sourceMappingURL=data:application/json;base64,${btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))} */`);
```

The key point here is `\n` is replaced with newline character (`0x0A`) and the second line starts with `/*# sourceMappingURL=`. This confuses `removeComments` API in [convert-source-map](https://github.com/thlorenz/convert-source-map/tree/master) package and it removes the second line:

```
sourceMap&&typeof btoa!="undefined"&&(css+=`

```

In this PR, we implement source map stripping based on that package's regex but add some heuristic checks to prevent false positives like above.
2023-08-07 16:05:39 +00:00
Vercel Release Bot
011f836aa7 [examples][tests] Upgrade Next.js to version 13.4.13 (#10308)
This auto-generated PR updates 3 packages to Next.js version 13.4.13
2023-08-07 15:12:14 +00:00
Trek Glowacki
ec107d7c91 Handle calls for deployment aliases when mocking deployment API (#10303)
Attempting to add tests to unblock a contributor https://github.com/vercel/vercel/pull/10236#issuecomment-1664183891 and finding a deployment also checks its aliases. This PR updates the mock deployment code to also create a handler for its aliases.
2023-08-07 14:34:49 +00:00
Shu Uesugi
0d27ae3b1a Remove unused code (#10309)
Reference was removed in https://github.com/vercel/vercel/pull/8377 but the code wasn't removed.
2023-08-07 14:10:22 +00:00
Vercel Release Bot
08da4b9c92 [remix] Update @remix-run/dev to v1.19.2 (#10299)
This auto-generated PR updates `@remix-run/dev` to version 1.19.2.
2023-08-04 23:17:40 +00:00
Trek Glowacki
877f09ff5c Be looser with mock server URLs (#10300)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
2023-08-04 10:20:33 -05:00
Vercel Release Bot
5cca9b6c5c Version Packages (#10289)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@31.2.2

### Patch Changes

- Migrate list command to new structure
([#10284](https://github.com/vercel/vercel/pull/10284))

- Migrate whoami command to new structure
([#10266](https://github.com/vercel/vercel/pull/10266))

- Migrate logs command to new structure
([#10281](https://github.com/vercel/vercel/pull/10281))

- Migrate login command to new structure
([#10283](https://github.com/vercel/vercel/pull/10283))

- Migrate pull command to new structure
([#10280](https://github.com/vercel/vercel/pull/10280))

- Migrate logout command to new structure
([#10282](https://github.com/vercel/vercel/pull/10282))

- Migrate build command to new structure
([#10286](https://github.com/vercel/vercel/pull/10286))

- Migrate inspect command to new structure
([#10277](https://github.com/vercel/vercel/pull/10277))

- Migrate redeploy command to new structure
([#10279](https://github.com/vercel/vercel/pull/10279))

- Migrate link command to new structure
([#10285](https://github.com/vercel/vercel/pull/10285))

- Update spacing of --help output for CLI
([#10287](https://github.com/vercel/vercel/pull/10287))

- Updated dependencies
\[[`4af242af8`](4af242af86),
[`0cbdae141`](0cbdae1411),
[`85dd66778`](85dd667781)]:
    -   @vercel/node@2.15.8
    -   @vercel/remix-builder@1.9.1
    -   @vercel/static-build@1.3.44

## @vercel/gatsby-plugin-vercel-builder@1.3.16

### Patch Changes

- Updated dependencies
\[[`4af242af8`](4af242af86),
[`85dd66778`](85dd667781)]:
    -   @vercel/node@2.15.8

## @vercel/node@2.15.8

### Patch Changes

- Move `@types/content-type` to dev dependency
([#10292](https://github.com/vercel/vercel/pull/10292))

- fix: compress condition
([#10288](https://github.com/vercel/vercel/pull/10288))

## @vercel/remix-builder@1.9.1

### Patch Changes

- Disable root workspace check in pnpm and yarn when adding deps
([#10291](https://github.com/vercel/vercel/pull/10291))

## @vercel/static-build@1.3.44

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@1.3.16

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-02 15:04:48 -05:00
Nathan Rajlich
4af242af86 [node] Move @types/content-type to dev dependency (#10292)
`@types/content-type` is only needed at build time.
2023-08-02 20:00:14 +00:00
Nathan Rajlich
0cbdae1411 [remix] Disable root workspace check in pnpm and yarn when adding deps (#10291)
The Remix application might _also_ be the root of a workspace, so check for that case and pass the appropriate flag to the package manager to make it not error.

See: https://github.com/orgs/vercel/discussions/3467
2023-08-02 18:36:38 +00:00
Kiko Beats
85dd667781 fix: compress condition (#10288)
I'm experiencing an issue due the condition is wrongly set.

When the response is buffered, it should be `compress: true` since we're acting as proxy, and we're going to recompress again.

When the response is streaming, then it should be `compress: false` since the response is going to be piped.
2023-08-02 18:15:16 +00:00
Trek Glowacki
7d3dda7341 [cli] Update spacing on --help output (#10287)
Indent more items rightwards to tidy up spacing.

Example of unmigrated `bisect` on current `main`:
<img width="561" alt="CleanShot 2023-07-31 at 14 47 38@2x" src="https://github.com/vercel/vercel/assets/9736/7474ac88-775c-43aa-937b-3f544c064c6d">

Migrated example (https://github.com/vercel/vercel/pull/10276) before changes in this PR:
<img width="661" alt="CleanShot 2023-07-31 at 15 07 26@2x" src="https://github.com/vercel/vercel/assets/9736/076b247c-35cf-45ea-8713-3c684b5063e4">


Migrated example after changes in this PR:
<img width="693" alt="CleanShot 2023-07-31 at 14 46 39@2x" src="https://github.com/vercel/vercel/assets/9736/f5f056a1-7f68-42e5-a724-79cf86031d09">
2023-08-02 17:33:59 +00:00
Vercel Release Bot
2144d0b2a9 [tests] Upgrade Turbo to version 1.10.12 (#10270)
This auto-generated PR updates Turbo to version 1.10.12
2023-08-02 17:12:33 +00:00
Trek Glowacki
976e6aedf9 [cli] Migrate link command to new structure (#10285)
Before:
<img width="785" alt="CleanShot 2023-07-31 at 09 55 03@2x" src="https://github.com/vercel/vercel/assets/9736/1f60cbcb-354f-4005-bb74-8ffd68a38fba">

After:
<img width="785" alt="CleanShot 2023-07-31 at 09 55 03@2x" src="https://github.com/vercel/vercel/assets/9736/4eea5e82-0304-4949-9e8f-aeaa1b2e74eb">
2023-08-02 16:48:24 +00:00
Trek Glowacki
6328751e14 [cli] Migrate whoami to new command structure (#10266)
Migrating `whoami` to the command structure created in #10090. Unsure about tests. This is technically a refactor so existing tests should suffice.
2023-08-02 14:21:57 +00:00
Trek Glowacki
8cb49a5136 [cli] Migrate logout command to new structure (#10282)
Co-authored-by: Trek Glowacki <trek.glowacki@vercel.com>
Co-authored-by: Chris Barber <chris.barber@vercel.com>
2023-08-02 08:59:49 -05:00
Trek Glowacki
3fa4f344cc [cli] Migrate pull command to new structure (#10280)
Before:
<img width="797" alt="CleanShot 2023-07-31 at 09 23 44@2x" src="https://github.com/vercel/vercel/assets/9736/88edd229-0aab-4155-9739-de64ad42e2f0">

After:
<img width="765" alt="CleanShot 2023-07-31 at 09 23 59@2x" src="https://github.com/vercel/vercel/assets/9736/574d0af0-5ce4-48dd-ad59-c4ca9893c147">
2023-08-01 20:24:25 +00:00
Trek Glowacki
27610896ed [cli] Migrate inspect command to new structure (#10277)
Before:
<img width="659" alt="CleanShot 2023-07-31 at 10 06 01@2x" src="https://github.com/vercel/vercel/assets/9736/32c91a94-9ae7-479c-8255-e4b554badd2f">


After:
<img width="664" alt="CleanShot 2023-07-31 at 10 06 11@2x" src="https://github.com/vercel/vercel/assets/9736/9237b42a-a015-4d58-8231-5e257342ac90">
2023-08-01 20:05:11 +00:00
Trek Glowacki
b9dae36e37 [cli] Migrate logs command to new structure (#10281)
Before:
<img width="669" alt="CleanShot 2023-07-31 at 09 36 25@2x" src="https://github.com/vercel/vercel/assets/9736/ee28d4b7-33eb-49cf-a565-fd4f56bf8bb6">

After:
<img width="693" alt="CleanShot 2023-07-31 at 09 36 46@2x" src="https://github.com/vercel/vercel/assets/9736/450d7c54-216f-4590-98b9-9f6b1a13d040">
2023-08-01 19:43:16 +00:00
Ilya Komichev
1537ff9c38 chore(README): set correct link to nuxt docs (#10265)
Co-authored-by: Chris Barber <chris.barber@vercel.com>
2023-08-01 13:46:39 -05:00
Trek Glowacki
7e0317775f [cli] Migrate build command to new structure (#10286)
Before:
<img width="854" alt="CleanShot 2023-07-31 at 09 59 18@2x" src="https://github.com/vercel/vercel/assets/9736/7a91572f-1481-4a2a-ac70-2384d6c30560">

After:
<img width="907" alt="CleanShot 2023-07-31 at 09 59 30@2x" src="https://github.com/vercel/vercel/assets/9736/ed358eae-9207-4ebe-ad41-865ce213560e">
2023-08-01 16:59:01 +00:00
Trek Glowacki
2dd27976b3 [cli] Migrate redeploy command to new structure (#10279)
Before:
<img width="816" alt="CleanShot 2023-07-31 at 09 19 16@2x" src="https://github.com/vercel/vercel/assets/9736/cf194706-8071-4f86-9a1c-896383a51a29">

After:
<img width="673" alt="CleanShot 2023-07-31 at 09 19 30@2x" src="https://github.com/vercel/vercel/assets/9736/d0f3faed-83e7-40b9-9252-c8b68855a7a3">
2023-08-01 16:37:32 +00:00
Trek Glowacki
25e2b7efba [cli] Migrate login command to new structure (#10283)
We currently incorrectly specify the argument is required with `<>`, but the examples show you can do `vercel login` without an argument, so I've corrected that as part of this migration.

Before:
<img width="549" alt="CleanShot 2023-07-31 at 09 44 28@2x" src="https://github.com/vercel/vercel/assets/9736/f1b1a328-69e0-4d61-b65c-d2739c81f61c">


After:
<img width="684" alt="CleanShot 2023-07-31 at 09 44 43@2x" src="https://github.com/vercel/vercel/assets/9736/e2bb28bf-e3d8-4d89-ad7e-864dd091ec3d">
2023-08-01 15:43:02 +00:00
Trek Glowacki
3d23d1270c [cli] Migrate list command to new structure (#10284)
Before:

<img width="809" alt="CleanShot 2023-07-31 at 09 51 37@2x" src="https://github.com/vercel/vercel/assets/9736/f5ac2ccc-3ff9-4a52-9c93-4a47fe479497">


After:
<img width="836" alt="CleanShot 2023-07-31 at 09 51 48@2x" src="https://github.com/vercel/vercel/assets/9736/48314715-132a-477a-8a66-a5d23c27ee50">
2023-07-31 22:21:11 +00:00
Vercel Release Bot
fde40e731a Version Packages (#10278)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-31 13:31:22 -05:00
Trek Glowacki
f353527421 [cli] Migrate bisect command to new structure (#10276)
Migrating `bisect` to the command structure created in https://github.com/vercel/vercel/pull/10090. Unsure about tests. This is technically a refactor so existing tests should suffice.

Before:
<img width="534" alt="CleanShot 2023-07-31 at 08 14 29@2x" src="https://github.com/vercel/vercel/assets/9736/8ae53672-9b1f-444a-94d3-296ac0fa8d30">

After:
<img width="674" alt="CleanShot 2023-07-31 at 08 15 02@2x" src="https://github.com/vercel/vercel/assets/9736/0ba12f19-fb34-41f3-84fb-0c1498d7a485">
2023-07-31 16:03:13 +00:00
Trek Glowacki
c1cdfb3e75 [cli] Migrate remove command to new structure (#10268)
Migrating `remove` to the command structure created in #10090. Unsure about tests. This is technically a refactor so existing tests should suffice.
2023-07-31 15:42:27 +00:00
Kiko Beats
fc413707d0 fix: move content-type as dependency (#10274)
It's required by `serverless-functions/helpers.js` causing unhandled
error because it's missing.

```
Error: Cannot find module 'content-type'
Require stack:
- /Users/kikobeats/Library/pnpm/global/5/.pnpm/@vercel+node@2.15.6/node_modules/@vercel/node/dist/serverless-functions/helpers.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/kikobeats/Library/pnpm/global/5/.pnpm/@cspotcode+source-map-support@0.8.1/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/Users/kikobeats/Library/pnpm/global/5/.pnpm/@vercel+node@2.15.6/node_modules/@vercel/node/dist/serverless-functions/helpers.js:6:24)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .js] (/Users/kikobeats/Library/pnpm/global/5/.pnpm/ts-node@10.9.1_@types+node@14.18.33_typescript@4.9.5/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1119:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/kikobeats/Library/pnpm/global/5/.pnpm/@vercel+node@2.15.6/node_modules/@vercel/node/dist/serverless-functions/helpers.js'
  ]
}
```
2023-07-31 16:11:18 +02:00
Vercel Release Bot
e842a8870e Version Packages (#10261)
# Releases
## vercel@31.2.0

### Minor Changes

- Add a "Global Options" section to help output
([#10250](https://github.com/vercel/vercel/pull/10250))

### Patch Changes

- Updated dependencies
\[[`d1b0dbe3a`](d1b0dbe3a7),
[`4a8622a10`](4a8622a10d),
[`6469ef1b8`](6469ef1b8c)]:
    -   @vercel/remix-builder@1.9.0
    -   @vercel/next@3.9.3

## @vercel/remix-builder@1.9.0

### Minor Changes

- Install `@vercel/remix-run-dev` at build-time instead of using symlink
([#9784](https://github.com/vercel/vercel/pull/9784))

### Patch Changes

- Update `@remix-run/dev` fork to v1.19.1
([#10246](https://github.com/vercel/vercel/pull/10246))

## @vercel/next@3.9.3

### Patch Changes

- fix dynamic not found pages
([#10262](https://github.com/vercel/vercel/pull/10262))
2023-07-28 15:40:19 -07:00
Nathan Rajlich
d1b0dbe3a7 [remix] Install @vercel/remix-run-dev at build-time instead of using symlink (#9784)
Instead of including the fork `@remix-run/dev` package as a regular dependency of `@vercel/remix-builder`, install it at build-time by modifying the project's `package.json` file. The reasons for this are:

* Avoids deprecation warnings from a few packages that currently exist on the `@remix-run/dev` package when installing Vercel CLI (those warnings already show up in the build logs anyways, so nothing new there).
* Allows us to install a version as close as possible to the version specified in the user's `package.json` (similar to how we do when auto-injecting the `@vercel/remix` package). This will be especially important once Remix v2 is released, which will have breaking changes compared to v1.

**Note:** `@vercel/remix-run-dev` is still a _dev_ dependency, so that we can use TypeScript types from it, as well as, at runtime, we use the version in the Builder's `package.json` to determine the maximum versions of `@vercel/remix-run-dev` and/or `@vercel/remix` which can safely be installed.

Fixes #10027.
Fixes #10222.
2023-07-28 20:49:32 +00:00
Chris Barber
d614709308 [codeowners] Add @trek to codeowners (#10267)
Adding Trek so he join in on the code review fun!
2023-07-28 13:28:45 -04:00
Trek Glowacki
d5b588bc06 [cli] Add a "Global Options" section to help output (#10250)
Followup PR to #10090. Some of our commands duplicate global options into their `args` structure e.g. 2661f56347/packages/cli/src/commands/logs.ts (L25-L26)

 Others commands omit it entirely.

This updates the `--help` output for commands migrated to our new structure (so far, only `deploy`) will show a "Global Options" section:

```
▲ vercel deploy [project-path] [options]

Deploy your project to Vercel. The `deploy` command is the default command for the Vercel CLI, and can be omitted (`vc deploy my-app` equals `vc my-app`).

Options

  --archive                    Compress the deployment code into a file before uploading it
  -b, --build-env <key=value>  Specify environment variables during build-time (e.g. `-b KEY1=value1 -b KEY2=value2`)
  -e, --env <key=value>        Specify environment variables during run-time (e.g. `-e KEY1=value1 -e KEY2=value2`)
  -f, --force                  Force a new deployment even if nothing has changed
  -m, --meta <key=value>       Specify metadata for the deployment (e.g. `-m KEY1=value1 -m KEY2=value2`)
  --no-wait                    Don't wait for the deployment to finish
  --prebuilt                   Use in combination with `vc build`. Deploy an existing build
  --prod                       Create a production deployment
  -p, --public                 Deployment is public (`/_src`) is exposed)
  --regions                    Set default regions to enable the deployment on
  --with-cache                 Retain build cache when using "--force"
  -y, --yes                    Use default options to skip all prompts

Global Options

  --cwd <DIR>                Sets the current working directory for a single run of a command
  -d, --debug                Debug mode (default off)
  -Q, --global-config <DIR>  Path to the global ${'`.vercel`'} directory
  -h, --help                 Output usage information
  -A, --local-config <FILE>  Path to the local `vercel.json` file
  --no-color                 No color mode (default off)
  -S, --scope                Set a custom scope
  -t, --token <TOKEN>        Login token
  -v, --version              Output the version number
```

As commands are migrated to this new structure, they'll gain this output automatically.
2023-07-27 20:48:07 +00:00
Zack Tanner
4a8622a10d [next] fix dynamic not found pages (#10262)
This updates `getServerlessPages` to consider `/_not-found` pages (which might opt into dynamic rendering)

- Corresponding Next.js changes https://github.com/vercel/next.js/pull/53231
- [slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1683763412272429)
2023-07-27 16:18:31 +00:00
Vercel Release Bot
6469ef1b8c [remix] Update @remix-run/dev to v1.19.1 (#10246)
This auto-generated PR updates `@remix-run/dev` to version 1.19.1.
2023-07-26 22:22:21 +00:00
Nathan Rajlich
b8d42a521b [examples] Remove "author" field from hydrogen template (#10253) 2023-07-26 14:48:07 -07:00
Vercel Release Bot
b1e8c9cb6e Version Packages (#10260)
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## vercel@31.1.1

### Patch Changes

- Updated dependencies
\[[`7c30b13cc`](7c30b13ccb)]:
    -   @vercel/next@3.9.2

## @vercel/next@3.9.2

### Patch Changes

- Fix pages/404 gsp + i18n case
([#10258](https://github.com/vercel/vercel/pull/10258))

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-26 14:50:22 -04:00
JJ Kasper
7c30b13ccb [next] Fix pages/404 gsp + i18n case (#10258)
This ensures we detect the locale prefixed 404 when it uses `getStaticProps` correctly. 

- x-ref: [slack thread](https://vercel.slack.com/archives/C05JTC58AQJ)
- Closes https://github.com/vercel/vercel/pull/10248
2023-07-26 18:41:25 +00:00
Steven
e5e757de34 [tests] fix vary header in next tests (#10249)
Since we run tests against canary, the latest [v13.4.13-canary.0](https://github.com/vercel/next.js/releases/tag/v13.4.13-canary.0) changed the `vary` header in https://github.com/vercel/next.js/pull/52746 so we need to update the tests to match.
2023-07-26 16:52:13 +00:00
Vercel Release Bot
2661f56347 Version Packages (#10227)
# Releases

## vercel@31.1.0

### Minor Changes

- Add 'Environment' column to 'vc list' with new '--environment' filter
and pipe URLs to stdout
([#10239](https://github.com/vercel/vercel/pull/10239))

### Patch Changes

- Update `proxy-agent` to v6.3.0
([#10226](https://github.com/vercel/vercel/pull/10226))

- Use `getNodeBinPaths()` in `vc dev`
([#10225](https://github.com/vercel/vercel/pull/10225))

- Updated dependencies
\[[`b1c14cde0`](b1c14cde03),
[`ce4633fe4`](ce4633fe4d)]:
    -   @vercel/next@3.9.1
    -   @vercel/static-build@1.3.42

## @vercel/frameworks@1.5.0

### Minor Changes

- Add `ignorePackageJsonScript` configuration for Framework command
settings to ignore the `package.json` script.
([#10228](https://github.com/vercel/vercel/pull/10228))

Enable this mode for Storybook's `buildCommand`, since it should not
invoke the "build" script, which is most likely designated for the
frontend app build.

## @vercel/fs-detectors@4.1.1

### Patch Changes

- Updated dependencies
\[[`ce4633fe4`](ce4633fe4d)]:
    -   @vercel/frameworks@1.5.0

## @vercel/next@3.9.1

### Patch Changes

- Fix pages and app router i18n handling
([#10243](https://github.com/vercel/vercel/pull/10243))

## @vercel/static-build@1.3.42

### Patch Changes

- Add `ignorePackageJsonScript` configuration for Framework command
settings to ignore the `package.json` script.
([#10228](https://github.com/vercel/vercel/pull/10228))

Enable this mode for Storybook's `buildCommand`, since it should not
invoke the "build" script, which is most likely designated for the
frontend app build.
2023-07-24 18:02:38 -07:00
JJ Kasper
b1c14cde03 [next] Fix pages and app router i18n handling (#10243)
Ensures app router paths are handled properly when i18n is configured for pages directory. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1687565759424049)
x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1687565759424049)
x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1672781549860349?thread_ts=1671393204.073649&cid=C03KAR5DCKC)

[VCCLI-780](https://linear.app/vercel/issue/VCCLI-780/add-404i18n-invariant-case-in-nextjs-builder)
2023-07-24 23:26:25 +00:00
Chris Barber
8dd6d021df [cli] Add "Environment" column to vc list (#10239)
Also adds a new `--environment=[preview|production]` filter and ability to pipe deployment URLs to `stdout`!

<img width="380" alt="image" src="https://github.com/vercel/vercel/assets/97262/20de0caa-2d63-4112-8213-cc15d23295c7">

```
vc list --environment preview
```

```
vc list --environment production
```

```
vc list --environment preview > preview_deployments.txt
```
2023-07-24 20:02:25 +00:00
Vercel Release Bot
88ec6e69d6 [examples][tests] Upgrade Next.js to version 13.4.12 (#10240)
This auto-generated PR updates 3 packages to Next.js version 13.4.12
2023-07-23 21:51:14 +00:00
Vercel Release Bot
a6f2e7b136 [tests] Upgrade Turbo to version 1.10.9 (#10241)
This auto-generated PR updates Turbo to version 1.10.9
2023-07-23 21:30:01 +00:00
Vercel Release Bot
e906365909 [examples][tests] Upgrade Next.js to version 13.4.11 (#10233)
This auto-generated PR updates 3 packages to Next.js version 13.4.11
2023-07-21 19:01:10 +00:00
Nathan Rajlich
7b01a07394 [cli] Use getNodeBinPaths() in vc dev (#10225)
This allows for the "dev command" of a Project to work better in monorepos, where the dev server might live up the node_modules hierarchy within the repo.
2023-07-19 22:19:43 +00:00
Nathan Rajlich
ce4633fe4d [frameworks][static-build] Add ignorePackageJsonScript configuration for Framework command settings (#10228)
When this property is set to `true`, then the corresponding `package.json` script will not be invoked, allowing for the default setting value will be executed.

This is enabled for Storybook's `buildCommand`, since we do not want the "build" script to be invoked, since that would belong to the frontend application's build instead of Storybook's.
2023-07-19 20:23:51 +00:00
Nathan Rajlich
fdf86fda03 [cli] Update proxy-agent to v6.3.0 (#10226)
This version includes a refactor for proxies specified via PAC files such that it no longer uses the deprecated `vm2` module.

See https://github.com/TooTallNate/proxy-agents/issues/218.
2023-07-18 20:29:37 +00:00
Vercel Release Bot
56178e6a46 Version Packages (#10213)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-18 14:02:19 -05:00
Nathan Rajlich
5439d7c0c9 [remix] Create ensured dependency symlink at the start directory, instead of root of repo (#10224)
When the `ensureResolvable()` function runs in a monorepo, the symlink should be created in the `node_modules` directory within the app subdirectory, rather than the root of the repository. Fixes the following issue:

![image](https://github.com/vercel/vercel/assets/71256/c0171533-881a-425e-85b9-82318ef19032)
2023-07-18 18:27:19 +00:00
Zack Tanner
c670e51712 [next] fix 404 page in edge runtime (#10223)
Fixes Next builder to handle edge runtime on 404 pages

[Related Next.js PR](https://github.com/vercel/next.js/pull/52754)
[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1689312606770609)
2023-07-17 19:48:45 +00:00
Kiko Beats
b56639b624 [node] fix: runs edge user code inside IIFE (#10220)
In this way, `self` is isolated and modify it doesn't break some Edge Runtime internals

Originally reported by @jawj at https://github.com/jawj/neon-vercel-zapatos-minimal-crash
2023-07-17 16:45:05 +00:00
Kiko Beats
12bbae098c [codeowners] @vercel/edge-compute → @vercel/compute (#10219) 2023-07-17 14:33:25 +00:00
Nathan Rajlich
9969f0ba18 [cli] Use detectFrameworks() during vc link --repo (#10203)
Allows for multiple frameworks to be detectable within the same root directory. This is basically specifically for Storybook.

<img width="700" alt="Screenshot 2023-07-12 at 6 04 37 PM" src="https://github.com/vercel/vercel/assets/71256/5a240f1e-b000-42ad-b36f-3c151d3cd449">
2023-07-14 18:11:49 +00:00
Vercel Release Bot
24e1e3c3be [examples][tests] Upgrade Next.js to version 13.4.10 (#10215)
This auto-generated PR updates 3 packages to Next.js version 13.4.10
2023-07-14 16:27:44 +00:00
Steven
b61674cb2d [tests] Fix next update cron job (#10214)
This was supposed to be fixed in https://github.com/vercel/vercel/pull/10173 but the file was created after git commit.

This PR makes sure the file is created before git commit.
2023-07-14 16:07:26 +00:00
Florentin / 珞辰
cae60155f3 [next] support maxDuration in Next.js deployments (#10069)
Follow up PR to
8703c55f9f
which reads the newly created function config manifest and patches in
the options for resource creation.

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-07-14 15:27:06 +02:00
584 changed files with 85053 additions and 19388 deletions

16
.github/CODEOWNERS vendored
View File

@@ -2,19 +2,19 @@
# https://help.github.com/en/articles/about-code-owners
# Restricted Paths
* @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood
/.github/workflows @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
/packages/fs-detectors @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @agadzik @chloetedder
/packages/next @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
/packages/routing-utils @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @ijjk
/packages/edge @vercel/edge-compute
* @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek
/.github/workflows @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek @ijjk
/packages/fs-detectors @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek @agadzik @chloetedder
/packages/next @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek @ijjk @ztanner
/packages/routing-utils @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek @ijjk
/packages/edge @vercel/compute
/examples @leerob
/examples/create-react-app @Timer
/examples/nextjs @timneutkens @ijjk @styfle
/examples/nextjs @timneutkens @ijjk @styfle @ztanner
/examples/hugo @styfle
/examples/jekyll @styfle
/examples/zola @styfle
/packages/node @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @Kikobeats
/packages/node @TooTallNate @EndangeredMassa @styfle @cb1kenobi @Ethan-Arrowood @trek @Kikobeats
# Unrestricted Paths
.changeset/

View File

@@ -2,7 +2,9 @@ body:
- type: markdown
attributes:
value: |
> **Note**: For discussions not related to Vercel CLI or Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions)
**Note**: This category is intended for discussions related to Vercel CLI or Runtimes.
If you post in this repository seeking help with other Vercel tools and features, it may be missed by our support team. For help with topics other than the CLI and Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions).
- type: textarea
attributes:
label: Description

View File

@@ -2,9 +2,11 @@ body:
- type: markdown
attributes:
value: |
> **Note**: For discussions not related to Vercel CLI or Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions/categories/help)
**Note**: This category is intended for discussions related to Vercel CLI or Runtimes.
If you post in this repository seeking help with other Vercel tools and features, it may be missed by our support team. For help with topics other than the CLI and Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions).
- type: textarea
attributes:
label: Problem Description
label: Question
validations:
required: true

View File

@@ -2,7 +2,9 @@ body:
- type: markdown
attributes:
value: |
> **Note**: For discussions not related to Vercel CLI or Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions/categories/ideas)
**Note**: This category is intended for sharing ideas related to Vercel CLI or Runtimes.
Please visit the [Vercel Community](https://github.com/orgs/vercel/discussions) to share ideas for other Vercel tools and features.
- type: textarea
attributes:
label: Idea

View File

@@ -1,10 +0,0 @@
body:
- type: markdown
attributes:
value: |
> **Note**: For discussions not related to Vercel CLI or Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions)
- type: textarea
attributes:
label: Description
validations:
required: true

View File

@@ -2,7 +2,9 @@ body:
- type: markdown
attributes:
value: |
> **Note**: For discussions not related to Vercel CLI or Runtimes, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions)
**Note**: This category is intended for discussions related to Vercel CLI or Runtimes.
For topics related to other Vercel features, please visit the [Vercel Community](https://github.com/orgs/vercel/discussions).
- type: textarea
attributes:
label: Description

View File

@@ -1,5 +0,0 @@
body:
- type: markdown
attributes:
value: |
> **Note**: This category should not be used for new discussions. Please visit the [Vercel Community](https://github.com/orgs/vercel/discussions)

View File

@@ -47,7 +47,6 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 360
check_interval: 5
test:
timeout-minutes: 120
runs-on: ${{ matrix.runner }}
@@ -75,19 +74,19 @@ jobs:
run: npm i -g pnpm@8.3.1
- run: pnpm install
- name: fetch ssl certificate before build (linux, os x)
if: matrix.runner != 'windows-latest'
run: echo | openssl s_client -showcerts -servername 'api.vercel.com' -connect 76.76.21.21:443
- name: Build ${{matrix.packageName}} and all its dependencies
run: node utils/gen.js && node_modules/.bin/turbo run build --cache-dir=".turbo" --scope=${{matrix.packageName}} --include-dependencies --no-deps
run: node utils/gen.js && node_modules/.bin/turbo run build --cache-dir=".turbo" --log-order=stream --scope=${{matrix.packageName}} --include-dependencies --no-deps
env:
FORCE_COLOR: '1'
- name: Test ${{matrix.packageName}}
run: node utils/gen.js && node_modules/.bin/turbo run test --cache-dir=".turbo" --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
run: node utils/gen.js && node_modules/.bin/turbo run test --cache-dir=".turbo" --log-order=stream --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
shell: bash
env:
JEST_JUNIT_OUTPUT_FILE: ${{github.workspace}}/.junit-reports/${{matrix.scriptName}}-${{matrix.packageName}}-${{matrix.chunkNumber}}-${{ matrix.runner }}.xml
VERCEL_CLI_VERSION: ${{ needs.setup.outputs.dplUrl }}/tarballs/vercel.tgz
VERCEL_TEST_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }}
VERCEL_TEST_REGISTRATION_URL: ${{ secrets.VERCEL_TEST_REGISTRATION_URL }}
@@ -97,6 +96,13 @@ jobs:
if: matrix.runner != 'windows-latest'
run: echo | openssl s_client -showcerts -servername 'api.vercel.com' -connect 76.76.21.21:443
- name: 'Upload Test Report to Datadog'
if: always()
run: 'npx @datadog/datadog-ci@2.18.1 junit upload --service vercel-cli .junit-reports'
env:
DATADOG_API_KEY: ${{secrets.DATADOG_API_KEY_CLI}}
DD_ENV: ci
summary:
name: Summary
runs-on: ubuntu-latest

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ __pycache__
.turbo
.eslintcache
turbo-cache-key.json
junit.xml

View File

@@ -387,7 +387,6 @@ This is an abstract enumeration type that is implemented by one of the following
- `nodejs18.x`
- `nodejs16.x`
- `nodejs14.x`
- `go1.x`
- `java11`
- `python3.9`

7
api/CHANGELOG.md Normal file
View File

@@ -0,0 +1,7 @@
# api
## 0.0.1
### Patch Changes
- fix RSC matching behavior & 404 status code on `fallback: false` ([#10388](https://github.com/vercel/vercel/pull/10388))

View File

@@ -1,7 +1,7 @@
{
"name": "api",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"description": "API for the vercel/vercel repo",
"main": "index.js",
"scripts": {},

View File

@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2021",
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,

7
examples/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,7 @@
# examples
## null
### Patch Changes
- update examples to use at least node@16 ([#10395](https://github.com/vercel/vercel/pull/10395))

View File

@@ -0,0 +1,5 @@
import { deployExample } from '../test-utils';
it('should deploy', async () => {
await deployExample(__filename);
});

View File

@@ -3,9 +3,10 @@
This directory is a brief example of an [Astro](https://astro.build/) site that can be deployed to Vercel with zero configuration. This demo showcases:
- `/` - A static page (pre-rendered)
- `/ssr` - A page that uses server-side rendering (through Vercel Edge Functions)
- `/ssr-with-swr-caching` - Similar to the previous page, but also caches the response on the Vercel Edge Network using `cache-control` headers
- `/edge.json` - An Astro API Endpoint that returns JSON data using Vercel Edge Functions
- `/ssr` - A page that uses server-side rendering (through [Vercel Edge Functions](https://vercel.com/docs/functions/edge-functions))
- `/ssr-with-swr-caching` - Similar to the previous page, but also caches the response on the [Vercel Edge Network](https://vercel.com/docs/edge-network/overview) using `cache-control` headers
- `/image` - Astro [Asset](https://docs.astro.build/en/guides/assets/) using Vercel [Image Optimization](https://vercel.com/docs/image-optimization)
- `/edge.json` - An Astro API Endpoint that returns JSON data using [Vercel Edge Functions](https://vercel.com/docs/functions/edge-functions)
Learn more about [Astro on Vercel](https://vercel.com/docs/frameworks/astro).

View File

@@ -1,7 +1,17 @@
import { defineConfig } from 'astro/config';
// Use Vercel Edge Functions (Recommended)
import vercel from '@astrojs/vercel/edge';
// Can also use Serverless Functions
// import vercel from '@astrojs/vercel/serverless';
// Or a completely static build
// import vercel from '@astrojs/vercel/static';
export default defineConfig({
output: 'server',
adapter: vercel(),
experimental: {
assets: true
},
adapter: vercel({
imageService: true,
}),
});

View File

@@ -8,8 +8,8 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/vercel": "3.2.2",
"astro": "^2.2.1",
"@astrojs/vercel": "3.8.2",
"astro": "^2.10.14",
"react": "18.2.0",
"web-vitals": "^3.3.1"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -1,4 +1,4 @@
/// <reference types="astro/client" />
/// <reference types="astro/client-image" />
interface ImportMetaEnv {
readonly PUBLIC_VERCEL_ANALYTICS_ID: string;

View File

@@ -0,0 +1,6 @@
---
import { Image } from 'astro:assets';
import astroLogo from '../assets/logo.png';
---
<Image src={astroLogo} alt="Astro Logo" width={50} quality={75} />

View File

@@ -4,7 +4,6 @@
root = true
[*]
end_of_line = lf
charset = utf-8

View File

@@ -5,5 +5,11 @@
Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
"disableAnalytics": false,
/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
}

View File

@@ -1,20 +1,13 @@
# unconventional js
/blueprints/*/files/
/vendor/
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
/node_modules/
# misc
/coverage/
!.*
.*/
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

View File

@@ -1,11 +1,24 @@
'use strict';
module.exports = {
root: true,
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 'latest',
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
],
},
},
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
@@ -14,14 +27,16 @@ module.exports = {
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'lib/*/index.js',
'server/**/*.js',
'./.eslintrc.js',
'./.prettierrc.js',
'./.stylelintrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./lib/*/index.js',
'./server/**/*.js',
],
parserOptions: {
sourceType: 'script',
@@ -30,18 +45,12 @@ module.exports = {
browser: false,
node: true,
},
plugins: ['node'],
rules: Object.assign(
{},
require('eslint-plugin-node').configs.recommended.rules,
{
// add your custom rules and overrides for node files here
// this can be removed once the following is fixed
// https://github.com/mysticatea/eslint-plugin-node/issues/77
'node/no-unpublished-require': 'off',
}
),
extends: ['plugin:n/recommended'],
},
{
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};

47
examples/ember/.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: CI
on:
push:
branches:
- main
- master
pull_request: {}
concurrency:
group: ci-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
lint:
name: "Lint"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- name: Install Dependencies
run: npm ci
- name: Lint
run: npm run lint
test:
name: "Test"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test

View File

@@ -1,32 +1,32 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
/node_modules/
# misc
/.env*
/.pnp*
/.sass-cache
/connect.lock
/.eslintcache
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
# broccoli-debug
/DEBUG/
# Environment Variables
.env
.env.build
.env.local
# Vercel
.vercel

View File

@@ -0,0 +1,13 @@
# unconventional js
/blueprints/*/files/
# compiled output
/dist/
# misc
/coverage/
!.*
.*/
# ember-try
/.node_modules.ember-try/

View File

@@ -0,0 +1,12 @@
'use strict';
module.exports = {
overrides: [
{
files: '*.{js,ts}',
options: {
singleQuote: true,
},
},
],
};

View File

@@ -0,0 +1,8 @@
# unconventional files
/blueprints/*/files/
# compiled output
/dist/
# addons
/.node_modules.ember-try/

View File

@@ -0,0 +1,5 @@
'use strict';
module.exports = {
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
};

View File

@@ -1,24 +0,0 @@
---
language: node_js
node_js:
- "8"
sudo: false
dist: trusty
addons:
chrome: stable
cache:
directories:
- $HOME/.npm
env:
global:
# See https://github.com/ember-cli/ember-cli/blob/master/docs/build-concurrency.md
- JOBS=1
script:
- npm run lint:hbs
- npm run lint:js
- npm test

View File

@@ -1,3 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
"ignore_dirs": ["dist"]
}

View File

@@ -14,7 +14,7 @@ _Live Example: https://ember-template.vercel.app_
### How We Created This Example
To get started with Ember for deployment with Vercel, you can use the [Ember CLI](https://ember-cli.com/) to initialize the project:
To get started with Ember for deployment with Vercel, you can use the [Ember CLI](https://cli.emberjs.com) to initialize the project:
```shell
$ npx ember-cli new ember-project

View File

@@ -1,14 +1,12 @@
import Application from '@ember/application';
import Resolver from './resolver';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
import config from 'ember-quickstart/config/environment';
const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver,
});
export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}
loadInitializers(App, config.modulePrefix);
export default App;

View File

@@ -1,16 +1,15 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>HelloWorld</title>
<title>EmberQuickstart</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/hello-world.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/ember-quickstart.css">
{{content-for "head-footer"}}
</head>
@@ -18,7 +17,7 @@
{{content-for "body"}}
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/hello-world.js"></script>
<script src="{{rootURL}}assets/ember-quickstart.js"></script>
{{content-for "body-footer"}}
</body>

View File

@@ -1,3 +0,0 @@
import Resolver from 'ember-resolver';
export default Resolver;

View File

@@ -1,11 +1,9 @@
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
import config from 'ember-quickstart/config/environment';
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL,
});
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}
Router.map(function() {});
export default Router;
Router.map(function () {});

View File

@@ -0,0 +1 @@
/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */

View File

@@ -1,5 +1,7 @@
{{!-- The following component displays Ember's default welcome message. --}}
{{page-title "EmberQuickstart"}}
{{! The following component displays Ember's default welcome message. }}
<WelcomePage />
{{!-- Feel free to remove this! --}}
{{! Feel free to remove this! }}
{{outlet}}

View File

@@ -0,0 +1,20 @@
{
"schemaVersion": "1.0.0",
"packages": [
{
"name": "ember-cli",
"version": "5.1.0",
"blueprints": [
{
"name": "app",
"outputRepo": "https://github.com/ember-cli/ember-new-output",
"codemodsSource": "ember-app-codemods-manifest@1",
"isBaseBlueprint": true,
"options": [
"--ci-provider=github"
]
}
]
}
]
}

View File

@@ -1,20 +1,17 @@
'use strict';
module.exports = function(environment) {
let ENV = {
modulePrefix: 'hello-world',
module.exports = function (environment) {
const ENV = {
modulePrefix: 'ember-quickstart',
environment,
rootURL: '/',
locationType: 'auto',
locationType: 'history',
EmberENV: {
EXTEND_PROTOTYPES: false,
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},
APP: {

View File

@@ -1,3 +1,6 @@
{
"jquery-integration": true
"application-template-wrapper": false,
"default-async-observers": true,
"jquery-integration": false,
"template-only-glimmer-components": true
}

View File

@@ -6,13 +6,6 @@ const browsers = [
'last 1 Safari versions',
];
const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';
if (isCI || isProduction) {
browsers.push('ie 11');
}
module.exports = {
browsers,
};

View File

@@ -2,23 +2,13 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Add options here
'ember-welcome-page': {
enabled: true
}
});
// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
return app.toTree();
};

22894
examples/ember/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
{
"name": "hello-world",
"name": "ember-quickstart",
"version": "0.0.0",
"private": true,
"description": "Small description for hello-world goes here",
"description": "Small description for ember-quickstart goes here",
"repository": "",
"license": "MIT",
"author": "",
@@ -11,43 +11,66 @@
"test": "tests"
},
"scripts": {
"build": "ember build",
"build": "ember build --environment=production",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:css": "stylelint \"**/*.css\"",
"lint:css:fix": "concurrently \"npm:lint:css -- --fix\"",
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"dev": "ember serve --port $PORT",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "ember test"
"test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
"test:ember": "ember test"
},
"devDependencies": {
"@ember/jquery": "^0.6.0",
"@ember/optional-features": "^0.7.0",
"@babel/eslint-parser": "^7.22.5",
"@babel/plugin-proposal-decorators": "^7.22.5",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^3.1.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"broccoli-asset-rev": "^3.0.0",
"ember-ajax": "^5.0.0",
"ember-cli": "~3.11.0",
"ember-cli-app-version": "^3.2.0",
"ember-cli-babel": "^7.7.3",
"ember-cli-dependency-checker": "^3.1.0",
"ember-cli-eslint": "^5.1.0",
"ember-cli-htmlbars": "^3.0.1",
"ember-cli-htmlbars-inline-precompile": "^2.1.0",
"ember-cli-inject-live-reload": "^1.8.2",
"concurrently": "^8.2.0",
"ember-auto-import": "^2.6.3",
"ember-cli": "~5.1.0",
"ember-cli-app-version": "^6.0.1",
"ember-cli-babel": "^7.26.11",
"ember-cli-clean-css": "^2.0.0",
"ember-cli-dependency-checker": "^3.3.2",
"ember-cli-htmlbars": "^6.2.0",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-template-lint": "^1.0.0-beta.1",
"ember-cli-uglify": "^2.1.0",
"ember-data": "~3.11.0",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^2.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-qunit": "^4.4.1",
"ember-resolver": "^5.0.1",
"ember-source": "~3.11.1",
"ember-welcome-page": "^4.0.0",
"eslint-plugin-ember": "^6.2.0",
"eslint-plugin-node": "^9.0.1",
"ember-cli-terser": "^4.0.2",
"ember-data": "~5.1.0",
"ember-fetch": "^8.1.2",
"ember-load-initializers": "^2.1.2",
"ember-modifier": "^4.1.0",
"ember-page-title": "^7.0.0",
"ember-qunit": "^7.0.0",
"ember-resolver": "^10.1.1",
"ember-source": "~5.1.1",
"ember-template-lint": "^5.11.0",
"ember-welcome-page": "^7.0.2",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-ember": "^11.9.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-qunit": "^8.0.0",
"loader.js": "^4.7.0",
"qunit-dom": "^0.8.4"
"prettier": "^2.8.8",
"qunit": "^2.19.4",
"qunit-dom": "^2.0.0",
"stylelint": "^15.9.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-prettier": "^3.0.0",
"tracked-built-ins": "^3.1.1",
"webpack": "^5.88.1"
},
"engines": {
"node": "14.x"
"ember": {
"edition": "octane"
}
}

View File

@@ -1,15 +1,17 @@
'use strict';
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
browser_start_timeout: 120,
browser_args: {
Chrome: {
ci: [
// --no-sandbox is needed when running Chrome inside a container
process.env.CI ? '--no-sandbox' : null,
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-software-rasterizer',
'--mute-audio',

View File

@@ -0,0 +1,42 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';
// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.
function setupApplicationTest(hooks, options) {
upstreamSetupApplicationTest(hooks, options);
// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}
function setupRenderingTest(hooks, options) {
upstreamSetupRenderingTest(hooks, options);
// Additional setup for rendering tests can be done here.
}
function setupTest(hooks, options) {
upstreamSetupTest(hooks, options);
// Additional setup for unit tests can be done here.
}
export { setupApplicationTest, setupRenderingTest, setupTest };

View File

@@ -2,8 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>HelloWorld Tests</title>
<title>EmberQuickstart Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -11,7 +10,7 @@
{{content-for "test-head"}}
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/hello-world.css">
<link rel="stylesheet" href="{{rootURL}}assets/ember-quickstart.css">
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">
{{content-for "head-footer"}}
@@ -21,10 +20,17 @@
{{content-for "body"}}
{{content-for "test-body"}}
<script src="/testem.js" integrity=""></script>
<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>
<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/hello-world.js"></script>
<script src="{{rootURL}}assets/ember-quickstart.js"></script>
<script src="{{rootURL}}assets/tests.js"></script>
{{content-for "body-footer"}}

View File

@@ -1,8 +1,12 @@
import Application from '../app';
import config from '../config/environment';
import Application from 'ember-quickstart/app';
import config from 'ember-quickstart/config/environment';
import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';
setApplication(Application.create(config.APP));
setup(QUnit.assert);
start();

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
# The variables added in this file are only available locally in MiniOxygen
SESSION_SECRET="foobar"
PUBLIC_STORE_DOMAIN="mock.shop"

View File

@@ -0,0 +1,5 @@
build
node_modules
bin
*.d.ts
dist

View File

@@ -0,0 +1,18 @@
/**
* @type {import("@types/eslint").Linter.BaseConfig}
*/
module.exports = {
extends: [
'@remix-run/eslint-config',
'plugin:hydrogen/recommended',
'plugin:hydrogen/typescript',
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/naming-convention': 'off',
'hydrogen/prefer-image-component': 'off',
'no-useless-escape': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'no-case-declarations': 'off',
},
};

9
examples/hydrogen-2/.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
node_modules
/.cache
/build
/dist
/public/build
/.mf
.env
.shopify
.vercel

View File

@@ -0,0 +1 @@
schema: node_modules/@shopify/hydrogen-react/storefront.schema.json

View File

@@ -0,0 +1,3 @@
.cache
dist
.shopify

View File

@@ -0,0 +1,48 @@
# Hydrogen v2
This directory is a brief example of a [Hydrogen v2](https://shopify.dev/custom-storefronts/hydrogen) storefront that can be deployed to Vercel with zero configuration.
## Deploy Your Own
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/vercel/tree/main/examples/hydrogen-2&template=hydrogen-2)
_Live Example: https://hydrogen-v2-template.vercel.app_
You can also deploy using the [Vercel CLI](https://vercel.com/cli):
```sh
npm i -g vercel
vercel
```
Hydrogen is Shopifys stack for headless commerce. Hydrogen is designed to dovetail with [Remix](https://remix.run/), Shopifys full stack web framework. This template contains a **minimal setup** of components, queries and tooling to get started with Hydrogen.
[Check out Hydrogen docs](https://shopify.dev/custom-storefronts/hydrogen)
[Get familiar with Remix](https://remix.run/docs/en/v1)
## What's included
- Remix
- Hydrogen
- Oxygen
- Shopify CLI
- ESLint
- Prettier
- GraphQL generator
- TypeScript and JavaScript flavors
- Minimal setup of components and routes
## Environment Variables
Using Hydrogen requires a few [environment variables](https://shopify.dev/docs/custom-storefronts/hydrogen/environment-variables) to be set in order to properly connect to Shopify. For this template, the minimal set of environment variables are defined in the `vercel.json` file, which will be applied to the deployment when deployed to Vercel. However, you should migrate these default environment variables to your Project's Environment Variables configuration in the Vercel dashboard (or using the `vc env` commands), and update them according to your needs (also change the `SESSION_SECRET` to your own value). Once that is done, delete the `vercel.json` file from your project to prevent the environment variables defined there from taking precedence.
## Local development
Rename the `.env.example` file to `.env` in order for the Shopify dev server to use those environment variables during local development. If you defined/modified additional environment variables based on the section above, be sure to apply those changes in your `.env` file as well.
Then run the following commands:
```bash
npm install
npm run dev
```

View File

@@ -0,0 +1,47 @@
/**
* A side bar component with Overlay that works without JavaScript.
* @example
* ```ts
* <Aside id="search-aside" heading="SEARCH">`
* <input type="search" />
* ...
* </Aside>
* ```
*/
export function Aside({
children,
heading,
id = 'aside',
}: {
children?: React.ReactNode;
heading: React.ReactNode;
id?: string;
}) {
return (
<div aria-modal className="overlay" id={id} role="dialog">
<button
className="close-outside"
onClick={() => {
history.go(-1);
window.location.hash = '';
}}
/>
<aside>
<header>
<h3>{heading}</h3>
<CloseAside />
</header>
<main>{children}</main>
</aside>
</div>
);
}
function CloseAside() {
return (
/* eslint-disable-next-line jsx-a11y/anchor-is-valid */
<a className="close" href="#" onChange={() => history.go(-1)}>
&times;
</a>
);
}

View File

@@ -0,0 +1,340 @@
import {CartForm, Image, Money} from '@shopify/hydrogen';
import type {CartLineUpdateInput} from '@shopify/hydrogen/storefront-api-types';
import {Link} from '@remix-run/react';
import type {CartApiQueryFragment} from 'storefrontapi.generated';
import {useVariantUrl} from '~/utils';
type CartLine = CartApiQueryFragment['lines']['nodes'][0];
type CartMainProps = {
cart: CartApiQueryFragment | null;
layout: 'page' | 'aside';
};
export function CartMain({layout, cart}: CartMainProps) {
const linesCount = Boolean(cart?.lines?.nodes?.length || 0);
const withDiscount =
cart &&
Boolean(cart.discountCodes.filter((code) => code.applicable).length);
const className = `cart-main ${withDiscount ? 'with-discount' : ''}`;
return (
<div className={className}>
<CartEmpty hidden={linesCount} layout={layout} />
<CartDetails cart={cart} layout={layout} />
</div>
);
}
function CartDetails({layout, cart}: CartMainProps) {
const cartHasItems = !!cart && cart.totalQuantity > 0;
return (
<div className="cart-details">
<CartLines lines={cart?.lines} layout={layout} />
{cartHasItems && (
<CartSummary cost={cart.cost} layout={layout}>
<CartDiscounts discountCodes={cart.discountCodes} />
<CartCheckoutActions checkoutUrl={cart.checkoutUrl} />
</CartSummary>
)}
</div>
);
}
function CartLines({
lines,
layout,
}: {
layout: CartMainProps['layout'];
lines: CartApiQueryFragment['lines'] | undefined;
}) {
if (!lines) return null;
return (
<div aria-labelledby="cart-lines">
<ul>
{lines.nodes.map((line) => (
<CartLineItem key={line.id} line={line} layout={layout} />
))}
</ul>
</div>
);
}
function CartLineItem({
layout,
line,
}: {
layout: CartMainProps['layout'];
line: CartLine;
}) {
const {id, merchandise} = line;
const {product, title, image, selectedOptions} = merchandise;
const lineItemUrl = useVariantUrl(product.handle, selectedOptions);
return (
<li key={id} className="cart-line">
{image && (
<Image
alt={title}
aspectRatio="1/1"
data={image}
height={100}
loading="lazy"
width={100}
/>
)}
<div>
<Link
prefetch="intent"
to={lineItemUrl}
onClick={() => {
if (layout === 'aside') {
// close the drawer
window.location.href = lineItemUrl;
}
}}
>
<p>
<strong>{product.title}</strong>
</p>
</Link>
<CartLinePrice line={line} as="span" />
<ul>
{selectedOptions.map((option) => (
<li key={option.name}>
<small>
{option.name}: {option.value}
</small>
</li>
))}
</ul>
<CartLineQuantity line={line} />
</div>
</li>
);
}
function CartCheckoutActions({checkoutUrl}: {checkoutUrl: string}) {
if (!checkoutUrl) return null;
return (
<div>
<a href={checkoutUrl} target="_self">
<p>Continue to Checkout &rarr;</p>
</a>
<br />
</div>
);
}
export function CartSummary({
cost,
layout,
children = null,
}: {
children?: React.ReactNode;
cost: CartApiQueryFragment['cost'];
layout: CartMainProps['layout'];
}) {
const className =
layout === 'page' ? 'cart-summary-page' : 'cart-summary-aside';
return (
<div aria-labelledby="cart-summary" className={className}>
<h4>Totals</h4>
<dl className="cart-subtotal">
<dt>Subtotal</dt>
<dd>
{cost?.subtotalAmount?.amount ? (
<Money data={cost?.subtotalAmount} />
) : (
'-'
)}
</dd>
</dl>
{children}
</div>
);
}
function CartLineRemoveButton({lineIds}: {lineIds: string[]}) {
return (
<CartForm
route="/cart"
action={CartForm.ACTIONS.LinesRemove}
inputs={{lineIds}}
>
<button type="submit">Remove</button>
</CartForm>
);
}
function CartLineQuantity({line}: {line: CartLine}) {
if (!line || typeof line?.quantity === 'undefined') return null;
const {id: lineId, quantity} = line;
const prevQuantity = Number(Math.max(0, quantity - 1).toFixed(0));
const nextQuantity = Number((quantity + 1).toFixed(0));
return (
<div className="cart-line-quantiy">
<small>Quantity: {quantity} &nbsp;&nbsp;</small>
<CartLineUpdateButton lines={[{id: lineId, quantity: prevQuantity}]}>
<button
aria-label="Decrease quantity"
disabled={quantity <= 1}
name="decrease-quantity"
value={prevQuantity}
>
<span>&#8722; </span>
</button>
</CartLineUpdateButton>
&nbsp;
<CartLineUpdateButton lines={[{id: lineId, quantity: nextQuantity}]}>
<button
aria-label="Increase quantity"
name="increase-quantity"
value={nextQuantity}
>
<span>&#43;</span>
</button>
</CartLineUpdateButton>
&nbsp;
<CartLineRemoveButton lineIds={[lineId]} />
</div>
);
}
function CartLinePrice({
line,
priceType = 'regular',
...passthroughProps
}: {
line: CartLine;
priceType?: 'regular' | 'compareAt';
[key: string]: any;
}) {
if (!line?.cost?.amountPerQuantity || !line?.cost?.totalAmount) return null;
const moneyV2 =
priceType === 'regular'
? line.cost.totalAmount
: line.cost.compareAtAmountPerQuantity;
if (moneyV2 == null) {
return null;
}
return (
<div>
<Money withoutTrailingZeros {...passthroughProps} data={moneyV2} />
</div>
);
}
export function CartEmpty({
hidden = false,
layout = 'aside',
}: {
hidden: boolean;
layout?: CartMainProps['layout'];
}) {
return (
<div hidden={hidden}>
<br />
<p>
Looks like you haven&rsquo;t added anything yet, let&rsquo;s get you
started!
</p>
<br />
<Link
to="/collections"
onClick={() => {
if (layout === 'aside') {
window.location.href = '/collections';
}
}}
>
Continue shopping
</Link>
</div>
);
}
function CartDiscounts({
discountCodes,
}: {
discountCodes: CartApiQueryFragment['discountCodes'];
}) {
const codes: string[] =
discountCodes
?.filter((discount) => discount.applicable)
?.map(({code}) => code) || [];
return (
<div>
{/* Have existing discount, display it with a remove option */}
<dl hidden={!codes.length}>
<div>
<dt>Discount(s)</dt>
<UpdateDiscountForm>
<div className="cart-discount">
<code>{codes?.join(', ')}</code>
&nbsp;
<button>Remove</button>
</div>
</UpdateDiscountForm>
</div>
</dl>
{/* Show an input to apply a discount */}
<UpdateDiscountForm discountCodes={codes}>
<div>
<input type="text" name="discountCode" placeholder="Discount code" />
&nbsp;
<button type="submit">Apply</button>
</div>
</UpdateDiscountForm>
</div>
);
}
function UpdateDiscountForm({
discountCodes,
children,
}: {
discountCodes?: string[];
children: React.ReactNode;
}) {
return (
<CartForm
route="/cart"
action={CartForm.ACTIONS.DiscountCodesUpdate}
inputs={{
discountCodes: discountCodes || [],
}}
>
{children}
</CartForm>
);
}
function CartLineUpdateButton({
children,
lines,
}: {
children: React.ReactNode;
lines: CartLineUpdateInput[];
}) {
return (
<CartForm
route="/cart"
action={CartForm.ACTIONS.LinesUpdate}
inputs={{lines}}
>
{children}
</CartForm>
);
}

View File

@@ -0,0 +1,99 @@
import {useMatches, NavLink} from '@remix-run/react';
import type {FooterQuery} from 'storefrontapi.generated';
export function Footer({menu}: FooterQuery) {
return (
<footer className="footer">
<FooterMenu menu={menu} />
</footer>
);
}
function FooterMenu({menu}: Pick<FooterQuery, 'menu'>) {
const [root] = useMatches();
const publicStoreDomain = root?.data?.publicStoreDomain;
return (
<nav className="footer-menu" role="navigation">
{(menu || FALLBACK_FOOTER_MENU).items.map((item) => {
if (!item.url) return null;
// if the url is internal, we strip the domain
const url =
item.url.includes('myshopify.com') ||
item.url.includes(publicStoreDomain)
? new URL(item.url).pathname
: item.url;
const isExternal = !url.startsWith('/');
return isExternal ? (
<a href={url} key={item.id} rel="noopener noreferrer" target="_blank">
{item.title}
</a>
) : (
<NavLink
end
key={item.id}
prefetch="intent"
style={activeLinkStyle}
to={url}
>
{item.title}
</NavLink>
);
})}
</nav>
);
}
const FALLBACK_FOOTER_MENU = {
id: 'gid://shopify/Menu/199655620664',
items: [
{
id: 'gid://shopify/MenuItem/461633060920',
resourceId: 'gid://shopify/ShopPolicy/23358046264',
tags: [],
title: 'Privacy Policy',
type: 'SHOP_POLICY',
url: '/policies/privacy-policy',
items: [],
},
{
id: 'gid://shopify/MenuItem/461633093688',
resourceId: 'gid://shopify/ShopPolicy/23358013496',
tags: [],
title: 'Refund Policy',
type: 'SHOP_POLICY',
url: '/policies/refund-policy',
items: [],
},
{
id: 'gid://shopify/MenuItem/461633126456',
resourceId: 'gid://shopify/ShopPolicy/23358111800',
tags: [],
title: 'Shipping Policy',
type: 'SHOP_POLICY',
url: '/policies/shipping-policy',
items: [],
},
{
id: 'gid://shopify/MenuItem/461633159224',
resourceId: 'gid://shopify/ShopPolicy/23358079032',
tags: [],
title: 'Terms of Service',
type: 'SHOP_POLICY',
url: '/policies/terms-of-service',
items: [],
},
],
};
function activeLinkStyle({
isActive,
isPending,
}: {
isActive: boolean;
isPending: boolean;
}) {
return {
fontWeight: isActive ? 'bold' : '',
color: isPending ? 'grey' : 'white',
};
}

View File

@@ -0,0 +1,178 @@
import {Await, NavLink, useMatches} from '@remix-run/react';
import {Suspense} from 'react';
import type {LayoutProps} from './Layout';
type HeaderProps = Pick<LayoutProps, 'header' | 'cart' | 'isLoggedIn'>;
type Viewport = 'desktop' | 'mobile';
export function Header({header, isLoggedIn, cart}: HeaderProps) {
const {shop, menu} = header;
return (
<header className="header">
<NavLink prefetch="intent" to="/" style={activeLinkStyle} end>
<strong>{shop.name}</strong>
</NavLink>
<HeaderMenu menu={menu} viewport="desktop" />
<HeaderCtas isLoggedIn={isLoggedIn} cart={cart} />
</header>
);
}
export function HeaderMenu({
menu,
viewport,
}: {
menu: HeaderProps['header']['menu'];
viewport: Viewport;
}) {
const [root] = useMatches();
const publicStoreDomain = root?.data?.publicStoreDomain;
const className = `header-menu-${viewport}`;
function closeAside(event: React.MouseEvent<HTMLAnchorElement>) {
if (viewport === 'mobile') {
event.preventDefault();
window.location.href = event.currentTarget.href;
}
}
return (
<nav className={className} role="navigation">
{viewport === 'mobile' && (
<NavLink
end
onClick={closeAside}
prefetch="intent"
style={activeLinkStyle}
to="/"
>
Home
</NavLink>
)}
{(menu || FALLBACK_HEADER_MENU).items.map((item) => {
if (!item.url) return null;
// if the url is internal, we strip the domain
const url =
item.url.includes('myshopify.com') ||
item.url.includes(publicStoreDomain)
? new URL(item.url).pathname
: item.url;
return (
<NavLink
className="header-menu-item"
end
key={item.id}
onClick={closeAside}
prefetch="intent"
style={activeLinkStyle}
to={url}
>
{item.title}
</NavLink>
);
})}
</nav>
);
}
function HeaderCtas({
isLoggedIn,
cart,
}: Pick<HeaderProps, 'isLoggedIn' | 'cart'>) {
return (
<nav className="header-ctas" role="navigation">
<HeaderMenuMobileToggle />
<NavLink prefetch="intent" to="/account" style={activeLinkStyle}>
{isLoggedIn ? 'Account' : 'Sign in'}
</NavLink>
<SearchToggle />
<CartToggle cart={cart} />
</nav>
);
}
function HeaderMenuMobileToggle() {
return (
<a className="header-menu-mobile-toggle" href="#mobile-menu-aside">
<h3></h3>
</a>
);
}
function SearchToggle() {
return <a href="#search-aside">Search</a>;
}
function CartBadge({count}: {count: number}) {
return <a href="#cart-aside">Cart {count}</a>;
}
function CartToggle({cart}: Pick<HeaderProps, 'cart'>) {
return (
<Suspense fallback={<CartBadge count={0} />}>
<Await resolve={cart}>
{(cart) => {
if (!cart) return <CartBadge count={0} />;
return <CartBadge count={cart.totalQuantity || 0} />;
}}
</Await>
</Suspense>
);
}
const FALLBACK_HEADER_MENU = {
id: 'gid://shopify/Menu/199655587896',
items: [
{
id: 'gid://shopify/MenuItem/461609500728',
resourceId: null,
tags: [],
title: 'Collections',
type: 'HTTP',
url: '/collections',
items: [],
},
{
id: 'gid://shopify/MenuItem/461609533496',
resourceId: null,
tags: [],
title: 'Blog',
type: 'HTTP',
url: '/blogs/journal',
items: [],
},
{
id: 'gid://shopify/MenuItem/461609566264',
resourceId: null,
tags: [],
title: 'Policies',
type: 'HTTP',
url: '/policies',
items: [],
},
{
id: 'gid://shopify/MenuItem/461609599032',
resourceId: 'gid://shopify/Page/92591030328',
tags: [],
title: 'About',
type: 'PAGE',
url: '/pages/about',
items: [],
},
],
};
function activeLinkStyle({
isActive,
isPending,
}: {
isActive: boolean;
isPending: boolean;
}) {
return {
fontWeight: isActive ? 'bold' : '',
color: isPending ? 'grey' : 'black',
};
}

View File

@@ -0,0 +1,95 @@
import {Await} from '@remix-run/react';
import {Suspense} from 'react';
import type {
CartApiQueryFragment,
FooterQuery,
HeaderQuery,
} from 'storefrontapi.generated';
import {Aside} from '~/components/Aside';
import {Footer} from '~/components/Footer';
import {Header, HeaderMenu} from '~/components/Header';
import {CartMain} from '~/components/Cart';
import {
PredictiveSearchForm,
PredictiveSearchResults,
} from '~/components/Search';
export type LayoutProps = {
cart: Promise<CartApiQueryFragment | null>;
children?: React.ReactNode;
footer: Promise<FooterQuery>;
header: HeaderQuery;
isLoggedIn: boolean;
};
export function Layout({
cart,
children = null,
footer,
header,
isLoggedIn,
}: LayoutProps) {
return (
<>
<CartAside cart={cart} />
<SearchAside />
<MobileMenuAside menu={header.menu} />
<Header header={header} cart={cart} isLoggedIn={isLoggedIn} />
<main>{children}</main>
<Suspense>
<Await resolve={footer}>
{(footer) => <Footer menu={footer.menu} />}
</Await>
</Suspense>
</>
);
}
function CartAside({cart}: {cart: LayoutProps['cart']}) {
return (
<Aside id="cart-aside" heading="CART">
<Suspense fallback={<p>Loading cart ...</p>}>
<Await resolve={cart}>
{(cart) => {
return <CartMain cart={cart} layout="aside" />;
}}
</Await>
</Suspense>
</Aside>
);
}
function SearchAside() {
return (
<Aside id="search-aside" heading="SEARCH">
<div className="predictive-search">
<br />
<PredictiveSearchForm>
{({fetchResults, inputRef}) => (
<div>
<input
name="q"
onChange={fetchResults}
onFocus={fetchResults}
placeholder="Search"
ref={inputRef}
type="search"
/>
&nbsp;
<button type="submit">Search</button>
</div>
)}
</PredictiveSearchForm>
<PredictiveSearchResults />
</div>
</Aside>
);
}
function MobileMenuAside({menu}: {menu: HeaderQuery['menu']}) {
return (
<Aside id="mobile-menu-aside" heading="MENU">
<HeaderMenu menu={menu} viewport="mobile" />
</Aside>
);
}

View File

@@ -0,0 +1,480 @@
import {
useParams,
useFetcher,
Link,
Form,
type FormProps,
} from '@remix-run/react';
import {Image, Money, Pagination} from '@shopify/hydrogen';
import React, {useRef, useEffect} from 'react';
import {useFetchers} from '@remix-run/react';
import type {
PredictiveProductFragment,
PredictiveCollectionFragment,
PredictiveArticleFragment,
SearchQuery,
} from 'storefrontapi.generated';
type PredicticeSearchResultItemImage =
| PredictiveCollectionFragment['image']
| PredictiveArticleFragment['image']
| PredictiveProductFragment['variants']['nodes'][0]['image'];
type PredictiveSearchResultItemPrice =
| PredictiveProductFragment['variants']['nodes'][0]['price'];
export type NormalizedPredictiveSearchResultItem = {
__typename: string | undefined;
handle: string;
id: string;
image?: PredicticeSearchResultItemImage;
price?: PredictiveSearchResultItemPrice;
styledTitle?: string;
title: string;
url: string;
};
export type NormalizedPredictiveSearchResults = Array<
| {type: 'queries'; items: Array<NormalizedPredictiveSearchResultItem>}
| {type: 'products'; items: Array<NormalizedPredictiveSearchResultItem>}
| {type: 'collections'; items: Array<NormalizedPredictiveSearchResultItem>}
| {type: 'pages'; items: Array<NormalizedPredictiveSearchResultItem>}
| {type: 'articles'; items: Array<NormalizedPredictiveSearchResultItem>}
>;
export type NormalizedPredictiveSearch = {
results: NormalizedPredictiveSearchResults;
totalResults: number;
};
type FetchSearchResultsReturn = {
searchResults: {
results: SearchQuery | null;
totalResults: number;
};
searchTerm: string;
};
export const NO_PREDICTIVE_SEARCH_RESULTS: NormalizedPredictiveSearchResults = [
{type: 'queries', items: []},
{type: 'products', items: []},
{type: 'collections', items: []},
{type: 'pages', items: []},
{type: 'articles', items: []},
];
export function SearchForm({searchTerm}: {searchTerm: string}) {
const inputRef = useRef<HTMLInputElement | null>(null);
// focus the input when cmd+k is pressed
useEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
if (event.key === 'k' && event.metaKey) {
event.preventDefault();
inputRef.current?.focus();
}
if (event.key === 'Escape') {
inputRef.current?.blur();
}
}
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, []);
return (
<Form method="get">
<input
defaultValue={searchTerm}
name="q"
placeholder="Search…"
ref={inputRef}
type="search"
/>
&nbsp;
<button type="submit">Search</button>
</Form>
);
}
export function SearchResults({
results,
}: Pick<FetchSearchResultsReturn['searchResults'], 'results'>) {
if (!results) {
return null;
}
const keys = Object.keys(results) as Array<keyof typeof results>;
return (
<div>
{results &&
keys.map((type) => {
const resourceResults = results[type];
if (resourceResults.nodes[0]?.__typename === 'Page') {
const pageResults = resourceResults as SearchQuery['pages'];
return resourceResults.nodes.length ? (
<SearchResultPageGrid key="pages" pages={pageResults} />
) : null;
}
if (resourceResults.nodes[0]?.__typename === 'Product') {
const productResults = resourceResults as SearchQuery['products'];
return resourceResults.nodes.length ? (
<SearchResultsProductsGrid
key="products"
products={productResults}
/>
) : null;
}
if (resourceResults.nodes[0]?.__typename === 'Article') {
const articleResults = resourceResults as SearchQuery['articles'];
return resourceResults.nodes.length ? (
<SearchResultArticleGrid
key="articles"
articles={articleResults}
/>
) : null;
}
return null;
})}
</div>
);
}
function SearchResultsProductsGrid({products}: Pick<SearchQuery, 'products'>) {
return (
<div className="search-result">
<h3>Products</h3>
<Pagination connection={products}>
{({nodes, isLoading, NextLink, PreviousLink}) => {
const itemsMarkup = nodes.map((product) => (
<div className="search-results-item" key={product.id}>
<Link prefetch="intent" to={`/products/${product.handle}`}>
<span>{product.title}</span>
</Link>
</div>
));
return (
<div>
<div>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
</div>
<div>
{itemsMarkup}
<br />
</div>
<div>
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</div>
</div>
);
}}
</Pagination>
<br />
</div>
);
}
function SearchResultPageGrid({pages}: Pick<SearchQuery, 'pages'>) {
return (
<div className="search-result">
<h2>Pages</h2>
<div>
{pages?.nodes?.map((page) => (
<div className="search-results-item" key={page.id}>
<Link prefetch="intent" to={`/pages/${page.handle}`}>
{page.title}
</Link>
</div>
))}
</div>
<br />
</div>
);
}
function SearchResultArticleGrid({articles}: Pick<SearchQuery, 'articles'>) {
return (
<div className="search-result">
<h2>Articles</h2>
<div>
{articles?.nodes?.map((article) => (
<div className="search-results-item" key={article.id}>
<Link prefetch="intent" to={`/blog/${article.handle}`}>
{article.title}
</Link>
</div>
))}
</div>
<br />
</div>
);
}
export function NoSearchResults() {
return <p>No results, try a different search.</p>;
}
type ChildrenRenderProps = {
fetchResults: (event: React.ChangeEvent<HTMLInputElement>) => void;
fetcher: ReturnType<typeof useFetcher<NormalizedPredictiveSearchResults>>;
inputRef: React.MutableRefObject<HTMLInputElement | null>;
};
type SearchFromProps = {
action?: FormProps['action'];
method?: FormProps['method'];
className?: string;
children: (passedProps: ChildrenRenderProps) => React.ReactNode;
[key: string]: unknown;
};
/**
* Search form component that posts search requests to the `/search` route
**/
export function PredictiveSearchForm({
action,
children,
className = 'predictive-search-form',
method = 'POST',
...props
}: SearchFromProps) {
const params = useParams();
const fetcher = useFetcher<NormalizedPredictiveSearchResults>();
const inputRef = useRef<HTMLInputElement | null>(null);
function fetchResults(event: React.ChangeEvent<HTMLInputElement>) {
const searchAction = action ?? '/api/predictive-search';
const localizedAction = params.locale
? `/${params.locale}${searchAction}`
: searchAction;
const newSearchTerm = event.target.value || '';
fetcher.submit(
{q: newSearchTerm, limit: '6'},
{method, action: localizedAction},
);
}
// ensure the passed input has a type of search, because SearchResults
// will select the element based on the input
useEffect(() => {
inputRef?.current?.setAttribute('type', 'search');
}, []);
return (
<fetcher.Form
{...props}
className={className}
onSubmit={(event) => {
event.preventDefault();
event.stopPropagation();
if (!inputRef?.current || inputRef.current.value === '') {
return;
}
inputRef.current.blur();
}}
>
{children({fetchResults, inputRef, fetcher})}
</fetcher.Form>
);
}
export function PredictiveSearchResults() {
const {results, totalResults, searchInputRef, searchTerm} =
usePredictiveSearch();
function goToSearchResult(event: React.MouseEvent<HTMLAnchorElement>) {
if (!searchInputRef.current) return;
searchInputRef.current.blur();
searchInputRef.current.value = '';
// close the aside
window.location.href = event.currentTarget.href;
}
if (!totalResults) {
return <NoPredictiveSearchResults searchTerm={searchTerm} />;
}
return (
<div className="predictive-search-results">
<div>
{results.map(({type, items}) => (
<PredictiveSearchResult
goToSearchResult={goToSearchResult}
items={items}
key={type}
searchTerm={searchTerm}
type={type}
/>
))}
</div>
{/* view all results /search?q=term */}
{searchTerm.current && (
<Link onClick={goToSearchResult} to={`/search?q=${searchTerm.current}`}>
<p>
View all results for <q>{searchTerm.current}</q>
&nbsp;
</p>
</Link>
)}
</div>
);
}
function NoPredictiveSearchResults({
searchTerm,
}: {
searchTerm: React.MutableRefObject<string>;
}) {
if (!searchTerm.current) {
return null;
}
return (
<p>
No results found for <q>{searchTerm.current}</q>
</p>
);
}
type SearchResultTypeProps = {
goToSearchResult: (event: React.MouseEvent<HTMLAnchorElement>) => void;
items: NormalizedPredictiveSearchResultItem[];
searchTerm: UseSearchReturn['searchTerm'];
type: NormalizedPredictiveSearchResults[number]['type'];
};
function PredictiveSearchResult({
goToSearchResult,
items,
searchTerm,
type,
}: SearchResultTypeProps) {
const isSuggestions = type === 'queries';
const categoryUrl = `/search?q=${
searchTerm.current
}&type=${pluralToSingularSearchType(type)}`;
return (
<div className="predictive-search-result" key={type}>
<Link prefetch="intent" to={categoryUrl} onClick={goToSearchResult}>
<h5>{isSuggestions ? 'Suggestions' : type}</h5>
</Link>
<ul>
{items.map((item: NormalizedPredictiveSearchResultItem) => (
<SearchResultItem
goToSearchResult={goToSearchResult}
item={item}
key={item.id}
/>
))}
</ul>
</div>
);
}
type SearchResultItemProps = Pick<SearchResultTypeProps, 'goToSearchResult'> & {
item: NormalizedPredictiveSearchResultItem;
};
function SearchResultItem({goToSearchResult, item}: SearchResultItemProps) {
return (
<li className="predictive-search-result-item" key={item.id}>
<Link onClick={goToSearchResult} to={item.url}>
{item.image?.url && (
<Image
alt={item.image.altText ?? ''}
src={item.image.url}
width={50}
height={50}
/>
)}
<div>
{item.styledTitle ? (
<div
dangerouslySetInnerHTML={{
__html: item.styledTitle,
}}
/>
) : (
<span>{item.title}</span>
)}
{item?.price && (
<small>
<Money data={item.price} />
</small>
)}
</div>
</Link>
</li>
);
}
type UseSearchReturn = NormalizedPredictiveSearch & {
searchInputRef: React.MutableRefObject<HTMLInputElement | null>;
searchTerm: React.MutableRefObject<string>;
};
function usePredictiveSearch(): UseSearchReturn {
const fetchers = useFetchers();
const searchTerm = useRef<string>('');
const searchInputRef = useRef<HTMLInputElement | null>(null);
const searchFetcher = fetchers.find((fetcher) => fetcher.data?.searchResults);
if (searchFetcher?.state === 'loading') {
searchTerm.current = (searchFetcher.formData?.get('q') || '') as string;
}
const search = (searchFetcher?.data?.searchResults || {
results: NO_PREDICTIVE_SEARCH_RESULTS,
totalResults: 0,
}) as NormalizedPredictiveSearch;
// capture the search input element as a ref
useEffect(() => {
if (searchInputRef.current) return;
searchInputRef.current = document.querySelector('input[type="search"]');
}, []);
return {...search, searchInputRef, searchTerm};
}
/**
* Converts a plural search type to a singular search type
* @param type - The plural search type
* @returns The singular search type
*
* @example
* ```ts
* pluralToSingularSearchType('articles') // => 'ARTICLE'
* pluralToSingularSearchType(['articles', 'products']) // => 'ARTICLE,PRODUCT'
* ```
*/
function pluralToSingularSearchType(
type:
| NormalizedPredictiveSearchResults[number]['type']
| Array<NormalizedPredictiveSearchResults[number]['type']>,
) {
const plural = {
articles: 'ARTICLE',
collections: 'COLLECTION',
pages: 'PAGE',
products: 'PRODUCT',
queries: 'QUERY',
};
if (typeof type === 'string') {
return plural[type];
}
return type.map((t) => plural[t]).join(',');
}

View File

@@ -0,0 +1,12 @@
import {RemixBrowser} from '@remix-run/react';
import {startTransition, StrictMode} from 'react';
import {hydrateRoot} from 'react-dom/client';
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>,
);
});

View File

@@ -0,0 +1,33 @@
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';
export default async function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
) {
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
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');
return new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
});
}

View File

@@ -0,0 +1,245 @@
import {defer, type LoaderArgs} from '@shopify/remix-oxygen';
import {
Links,
Meta,
Outlet,
Scripts,
useMatches,
useRouteError,
useLoaderData,
ScrollRestoration,
isRouteErrorResponse,
} from '@remix-run/react';
import type {CustomerAccessToken} from '@shopify/hydrogen-react/storefront-api-types';
import type {HydrogenSession} from '../server';
import favicon from '../public/favicon.svg';
import resetStyles from './styles/reset.css';
import appStyles from './styles/app.css';
import {Layout} from '~/components/Layout';
import tailwindCss from './styles/tailwind.css';
export function links() {
return [
{rel: 'stylesheet', href: tailwindCss},
{rel: 'stylesheet', href: resetStyles},
{rel: 'stylesheet', href: appStyles},
{
rel: 'preconnect',
href: 'https://cdn.shopify.com',
},
{
rel: 'preconnect',
href: 'https://shop.app',
},
{rel: 'icon', type: 'image/svg+xml', href: favicon},
];
}
export async function loader({context}: LoaderArgs) {
const {storefront, session, cart} = context;
const customerAccessToken = await session.get('customerAccessToken');
const publicStoreDomain = context.env.PUBLIC_STORE_DOMAIN;
// validate the customer access token is valid
const {isLoggedIn, headers} = await validateCustomerAccessToken(
customerAccessToken,
session,
);
// defer the cart query by not awaiting it
const cartPromise = cart.get();
// defer the footer query (below the fold)
const footerPromise = storefront.query(FOOTER_QUERY, {
cache: storefront.CacheLong(),
variables: {
footerMenuHandle: 'footer', // Adjust to your footer menu handle
},
});
// await the header query (above the fold)
const headerPromise = storefront.query(HEADER_QUERY, {
cache: storefront.CacheLong(),
variables: {
headerMenuHandle: 'main-menu', // Adjust to your header menu handle
},
});
return defer(
{
cart: cartPromise,
footer: footerPromise,
header: await headerPromise,
isLoggedIn,
publicStoreDomain,
},
{headers},
);
}
export default function App() {
const data = useLoaderData<typeof loader>();
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<Layout {...data}>
<Outlet />
</Layout>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export function ErrorBoundary() {
const error = useRouteError();
const [root] = useMatches();
let errorMessage = 'Unknown error';
let errorStatus = 500;
if (isRouteErrorResponse(error)) {
errorMessage = error?.data?.message ?? error.data;
errorStatus = error.status;
} else if (error instanceof Error) {
errorMessage = error.message;
}
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<Layout {...root.data}>
<div className="route-error">
<h1>Oops</h1>
<h2>{errorStatus}</h2>
{errorMessage && (
<fieldset>
<pre>{errorMessage}</pre>
</fieldset>
)}
</div>
</Layout>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
/**
* Validates the customer access token and returns a boolean and headers
* @see https://shopify.dev/docs/api/storefront/latest/objects/CustomerAccessToken
*
* @example
* ```ts
* //
* const {isLoggedIn, headers} = await validateCustomerAccessToken(
* customerAccessToken,
* session,
* );
* ```
* */
async function validateCustomerAccessToken(
customerAccessToken: CustomerAccessToken,
session: HydrogenSession,
) {
let isLoggedIn = false;
const headers = new Headers();
if (!customerAccessToken?.accessToken || !customerAccessToken?.expiresAt) {
return {isLoggedIn, headers};
}
const expiresAt = new Date(customerAccessToken.expiresAt);
const dateNow = new Date();
const customerAccessTokenExpired = expiresAt < dateNow;
if (customerAccessTokenExpired) {
session.unset('customerAccessToken');
headers.append('Set-Cookie', await session.commit());
} else {
isLoggedIn = true;
}
return {isLoggedIn, headers};
}
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;
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;
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;

View File

@@ -0,0 +1,7 @@
import type {LoaderArgs} from '@shopify/remix-oxygen';
export async function loader({request}: LoaderArgs) {
throw new Response(`${new URL(request.url).pathname} not found`, {
status: 404,
});
}

View File

@@ -0,0 +1,145 @@
import {type LoaderArgs} from '@shopify/remix-oxygen';
import {useRouteError, isRouteErrorResponse} from '@remix-run/react';
import {parseGid} from '@shopify/hydrogen';
export async function loader({request, context}: LoaderArgs) {
const url = new URL(request.url);
const {shop} = await context.storefront.query(ROBOTS_QUERY);
const shopId = parseGid(shop.id).id;
const body = robotsTxtData({url: url.origin, shopId});
return new Response(body, {
status: 200,
headers: {
'Content-Type': 'text/plain',
'Cache-Control': `max-age=${60 * 60 * 24}`,
},
});
}
export function ErrorBoundary() {
const error = useRouteError();
if (isRouteErrorResponse(error)) {
return (
<div>
<h1>Oops</h1>
<p>Status: {error.status}</p>
<p>{error.data.message}</p>
</div>
);
}
let errorMessage = 'Unknown error';
if (error instanceof Error) {
errorMessage = error.message;
}
return (
<div>
<h1>Uh oh ...</h1>
<p>Something went wrong.</p>
<pre>{errorMessage}</pre>
</div>
);
}
function robotsTxtData({url, shopId}: {shopId?: string; url?: string}) {
const sitemapUrl = url ? `${url}/sitemap.xml` : undefined;
return `
User-agent: *
${generalDisallowRules({sitemapUrl, shopId})}
# Google adsbot ignores robots.txt unless specifically named!
User-agent: adsbot-google
Disallow: /checkouts/
Disallow: /checkout
Disallow: /carts
Disallow: /orders
${shopId ? `Disallow: /${shopId}/checkouts` : ''}
${shopId ? `Disallow: /${shopId}/orders` : ''}
Disallow: /*?*oseid=*
Disallow: /*preview_theme_id*
Disallow: /*preview_script_id*
User-agent: Nutch
Disallow: /
User-agent: AhrefsBot
Crawl-delay: 10
${generalDisallowRules({sitemapUrl, shopId})}
User-agent: AhrefsSiteAudit
Crawl-delay: 10
${generalDisallowRules({sitemapUrl, shopId})}
User-agent: MJ12bot
Crawl-Delay: 10
User-agent: Pinterest
Crawl-delay: 1
`.trim();
}
/**
* This function generates disallow rules that generally follow what Shopify's
* Online Store has as defaults for their robots.txt
*/
function generalDisallowRules({
shopId,
sitemapUrl,
}: {
shopId?: string;
sitemapUrl?: string;
}) {
return `Disallow: /admin
Disallow: /cart
Disallow: /orders
Disallow: /checkouts/
Disallow: /checkout
${shopId ? `Disallow: /${shopId}/checkouts` : ''}
${shopId ? `Disallow: /${shopId}/orders` : ''}
Disallow: /carts
Disallow: /account
Disallow: /collections/*sort_by*
Disallow: /*/collections/*sort_by*
Disallow: /collections/*+*
Disallow: /collections/*%2B*
Disallow: /collections/*%2b*
Disallow: /*/collections/*+*
Disallow: /*/collections/*%2B*
Disallow: /*/collections/*%2b*
Disallow: */collections/*filter*&*filter*
Disallow: /blogs/*+*
Disallow: /blogs/*%2B*
Disallow: /blogs/*%2b*
Disallow: /*/blogs/*+*
Disallow: /*/blogs/*%2B*
Disallow: /*/blogs/*%2b*
Disallow: /*?*oseid=*
Disallow: /*preview_theme_id*
Disallow: /*preview_script_id*
Disallow: /policies/
Disallow: /*/*?*ls=*&ls=*
Disallow: /*/*?*ls%3D*%3Fls%3D*
Disallow: /*/*?*ls%3d*%3fls%3d*
Disallow: /search
Allow: /search/
Disallow: /search/?*
Disallow: /apple-app-site-association
Disallow: /.well-known/shopify/monorail
${sitemapUrl ? `Sitemap: ${sitemapUrl}` : ''}`;
}
const ROBOTS_QUERY = `#graphql
query StoreRobots($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
shop {
id
}
}
` as const;

View File

@@ -0,0 +1,174 @@
import {flattenConnection} from '@shopify/hydrogen';
import type {LoaderArgs} from '@shopify/remix-oxygen';
import type {SitemapQuery} from 'storefrontapi.generated';
/**
* the google limit is 50K, however, the storefront API
* allows querying only 250 resources per pagination page
*/
const MAX_URLS = 250;
type Entry = {
url: string;
lastMod?: string;
changeFreq?: string;
image?: {
url: string;
title?: string;
caption?: string;
};
};
export async function loader({request, context: {storefront}}: LoaderArgs) {
const data = await storefront.query(SITEMAP_QUERY, {
variables: {
urlLimits: MAX_URLS,
language: storefront.i18n.language,
},
});
if (!data) {
throw new Response('No data found', {status: 404});
}
const sitemap = generateSitemap({data, baseUrl: new URL(request.url).origin});
return new Response(sitemap, {
headers: {
'Content-Type': 'application/xml',
'Cache-Control': `max-age=${60 * 60 * 24}`,
},
});
}
function xmlEncode(string: string) {
return string.replace(/[&<>'"]/g, (char) => `&#${char.charCodeAt(0)};`);
}
function generateSitemap({
data,
baseUrl,
}: {
data: SitemapQuery;
baseUrl: string;
}) {
const products = flattenConnection(data.products)
.filter((product) => product.onlineStoreUrl)
.map((product) => {
const url = `${baseUrl}/products/${xmlEncode(product.handle)}`;
const productEntry: Entry = {
url,
lastMod: product.updatedAt,
changeFreq: 'daily',
};
if (product.featuredImage?.url) {
productEntry.image = {
url: xmlEncode(product.featuredImage.url),
};
if (product.title) {
productEntry.image.title = xmlEncode(product.title);
}
if (product.featuredImage.altText) {
productEntry.image.caption = xmlEncode(product.featuredImage.altText);
}
}
return productEntry;
});
const collections = flattenConnection(data.collections)
.filter((collection) => collection.onlineStoreUrl)
.map((collection) => {
const url = `${baseUrl}/collections/${collection.handle}`;
return {
url,
lastMod: collection.updatedAt,
changeFreq: 'daily',
};
});
const pages = flattenConnection(data.pages)
.filter((page) => page.onlineStoreUrl)
.map((page) => {
const url = `${baseUrl}/pages/${page.handle}`;
return {
url,
lastMod: page.updatedAt,
changeFreq: 'weekly',
};
});
const urls = [...products, ...collections, ...pages];
return `
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
>
${urls.map(renderUrlTag).join('')}
</urlset>`;
}
function renderUrlTag({url, lastMod, changeFreq, image}: Entry) {
const imageTag = image
? `<image:image>
<image:loc>${image.url}</image:loc>
<image:title>${image.title ?? ''}</image:title>
<image:caption>${image.caption ?? ''}</image:caption>
</image:image>`.trim()
: '';
return `
<url>
<loc>${url}</loc>
<lastmod>${lastMod}</lastmod>
<changefreq>${changeFreq}</changefreq>
${imageTag}
</url>
`.trim();
}
const SITEMAP_QUERY = `#graphql
query Sitemap($urlLimits: Int, $language: LanguageCode)
@inContext(language: $language) {
products(
first: $urlLimits
query: "published_status:'online_store:visible'"
) {
nodes {
updatedAt
handle
onlineStoreUrl
title
featuredImage {
url
altText
}
}
}
collections(
first: $urlLimits
query: "published_status:'online_store:visible'"
) {
nodes {
updatedAt
handle
onlineStoreUrl
}
}
pages(first: $urlLimits, query: "published_status:'published'") {
nodes {
updatedAt
handle
onlineStoreUrl
}
}
}
` as const;

View File

@@ -0,0 +1,145 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {defer, type LoaderArgs} from '@shopify/remix-oxygen';
import {Await, useLoaderData, Link} from '@remix-run/react';
import {Suspense} from 'react';
import {Image, Money} from '@shopify/hydrogen';
import type {
FeaturedCollectionFragment,
RecommendedProductsQuery,
} from 'storefrontapi.generated';
export const meta: V2_MetaFunction = () => {
return [{title: 'Hydrogen | Home'}];
};
export async function loader({context}: LoaderArgs) {
const {storefront} = context;
const {collections} = await storefront.query(FEATURED_COLLECTION_QUERY);
const featuredCollection = collections.nodes[0];
const recommendedProducts = storefront.query(RECOMMENDED_PRODUCTS_QUERY);
return defer({featuredCollection, recommendedProducts});
}
export default function Homepage() {
const data = useLoaderData<typeof loader>();
return (
<div className="home">
<FeaturedCollection collection={data.featuredCollection} />
<RecommendedProducts products={data.recommendedProducts} />
</div>
);
}
function FeaturedCollection({
collection,
}: {
collection: FeaturedCollectionFragment;
}) {
const image = collection.image;
return (
<Link
className="featured-collection"
to={`/collections/${collection.handle}`}
>
{image && (
<div className="featured-collection-image">
<Image data={image} sizes="100vw" />
</div>
)}
<h1>{collection.title}</h1>
</Link>
);
}
function RecommendedProducts({
products,
}: {
products: Promise<RecommendedProductsQuery>;
}) {
return (
<div className="recommended-products">
<h2>Recommended Products</h2>
<Suspense fallback={<div>Loading...</div>}>
<Await resolve={products}>
{({products}) => (
<div className="recommended-products-grid">
{products.nodes.map((product) => (
<Link
key={product.id}
className="recommended-product"
to={`/products/${product.handle}`}
>
<Image
data={product.images.nodes[0]}
aspectRatio="1/1"
sizes="(min-width: 45em) 20vw, 50vw"
/>
<h4>{product.title}</h4>
<small>
<Money data={product.priceRange.minVariantPrice} />
</small>
</Link>
))}
</div>
)}
</Await>
</Suspense>
<br />
</div>
);
}
const FEATURED_COLLECTION_QUERY = `#graphql
fragment FeaturedCollection on Collection {
id
title
image {
id
url
altText
width
height
}
handle
}
query FeaturedCollection($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
collections(first: 1, sortKey: UPDATED_AT, reverse: true) {
nodes {
...FeaturedCollection
}
}
}
` as const;
const RECOMMENDED_PRODUCTS_QUERY = `#graphql
fragment RecommendedProduct on Product {
id
title
handle
priceRange {
minVariantPrice {
amount
currencyCode
}
}
images(first: 1) {
nodes {
id
url
altText
width
height
}
}
}
query RecommendedProducts ($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
products(first: 4, sortKey: UPDATED_AT, reverse: true) {
nodes {
...RecommendedProduct
}
}
}
` as const;

View File

@@ -0,0 +1,9 @@
import type {LoaderArgs} from '@shopify/remix-oxygen';
import {redirect} from '@shopify/remix-oxygen';
export async function loader({context}: LoaderArgs) {
if (await context.session.get('customerAccessToken')) {
return redirect('/account');
}
return redirect('/account/login');
}

View File

@@ -0,0 +1,563 @@
import type {MailingAddressInput} from '@shopify/hydrogen/storefront-api-types';
import type {AddressFragment, CustomerFragment} from 'storefrontapi.generated';
import {
json,
redirect,
type ActionArgs,
type LoaderArgs,
type V2_MetaFunction,
} from '@shopify/remix-oxygen';
import {
Form,
useActionData,
useNavigation,
useOutletContext,
} from '@remix-run/react';
export type ActionResponse = {
addressId?: string | null;
createdAddress?: AddressFragment;
defaultAddress?: string | null;
deletedAddress?: string | null;
error: Record<AddressFragment['id'], string> | null;
updatedAddress?: AddressFragment;
};
export const meta: V2_MetaFunction = () => {
return [{title: 'Addresses'}];
};
export async function loader({context}: LoaderArgs) {
const {session} = context;
const customerAccessToken = await session.get('customerAccessToken');
if (!customerAccessToken) {
return redirect('/account/login');
}
return json({});
}
export async function action({request, context}: ActionArgs) {
const {storefront, session} = context;
try {
const form = await request.formData();
const addressId = form.has('addressId')
? String(form.get('addressId'))
: null;
if (!addressId) {
throw new Error('You must provide an address id.');
}
const customerAccessToken = await session.get('customerAccessToken');
if (!customerAccessToken) {
return json({error: {[addressId]: 'Unauthorized'}}, {status: 401});
}
const {accessToken} = customerAccessToken;
const defaultAddress = form.has('defaultAddress')
? String(form.get('defaultAddress')) === 'on'
: null;
const address: MailingAddressInput = {};
const keys: (keyof MailingAddressInput)[] = [
'address1',
'address2',
'city',
'company',
'country',
'firstName',
'lastName',
'phone',
'province',
'zip',
];
for (const key of keys) {
const value = form.get(key);
if (typeof value === 'string') {
address[key] = value;
}
}
switch (request.method) {
case 'POST': {
// handle new address creation
try {
const {customerAddressCreate} = await storefront.mutate(
CREATE_ADDRESS_MUTATION,
{
variables: {customerAccessToken: accessToken, address},
},
);
if (customerAddressCreate?.customerUserErrors?.length) {
const error = customerAddressCreate.customerUserErrors[0];
throw new Error(error.message);
}
const createdAddress = customerAddressCreate?.customerAddress;
if (!createdAddress?.id) {
throw new Error(
'Expected customer address to be created, but the id is missing',
);
}
if (defaultAddress) {
const createdAddressId = decodeURIComponent(createdAddress.id);
const {customerDefaultAddressUpdate} = await storefront.mutate(
UPDATE_DEFAULT_ADDRESS_MUTATION,
{
variables: {
customerAccessToken: accessToken,
addressId: createdAddressId,
},
},
);
if (customerDefaultAddressUpdate?.customerUserErrors?.length) {
const error = customerDefaultAddressUpdate.customerUserErrors[0];
throw new Error(error.message);
}
}
return json({error: null, createdAddress, defaultAddress});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: {[addressId]: error.message}}, {status: 400});
}
return json({error: {[addressId]: error}}, {status: 400});
}
}
case 'PUT': {
// handle address updates
try {
const {customerAddressUpdate} = await storefront.mutate(
UPDATE_ADDRESS_MUTATION,
{
variables: {
address,
customerAccessToken: accessToken,
id: decodeURIComponent(addressId),
},
},
);
const updatedAddress = customerAddressUpdate?.customerAddress;
if (customerAddressUpdate?.customerUserErrors?.length) {
const error = customerAddressUpdate.customerUserErrors[0];
throw new Error(error.message);
}
if (defaultAddress) {
const {customerDefaultAddressUpdate} = await storefront.mutate(
UPDATE_DEFAULT_ADDRESS_MUTATION,
{
variables: {
customerAccessToken: accessToken,
addressId: decodeURIComponent(addressId),
},
},
);
if (customerDefaultAddressUpdate?.customerUserErrors?.length) {
const error = customerDefaultAddressUpdate.customerUserErrors[0];
throw new Error(error.message);
}
}
return json({error: null, updatedAddress, defaultAddress});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: {[addressId]: error.message}}, {status: 400});
}
return json({error: {[addressId]: error}}, {status: 400});
}
}
case 'DELETE': {
// handles address deletion
try {
const {customerAddressDelete} = await storefront.mutate(
DELETE_ADDRESS_MUTATION,
{
variables: {customerAccessToken: accessToken, id: addressId},
},
);
if (customerAddressDelete?.customerUserErrors?.length) {
const error = customerAddressDelete.customerUserErrors[0];
throw new Error(error.message);
}
return json({error: null, deletedAddress: addressId});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: {[addressId]: error.message}}, {status: 400});
}
return json({error: {[addressId]: error}}, {status: 400});
}
}
default: {
return json(
{error: {[addressId]: 'Method not allowed'}},
{status: 405},
);
}
}
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
}
export default function Addresses() {
const {customer} = useOutletContext<{customer: CustomerFragment}>();
const {defaultAddress, addresses} = customer;
return (
<div className="account-addresses">
<h2>Addresses</h2>
<br />
{!addresses.nodes.length ? (
<p>You have no addresses saved.</p>
) : (
<div>
<div>
<legend>Create address</legend>
<NewAddressForm />
</div>
<br />
<hr />
<br />
<ExistingAddresses
addresses={addresses}
defaultAddress={defaultAddress}
/>
</div>
)}
</div>
);
}
function NewAddressForm() {
const newAddress = {
address1: '',
address2: '',
city: '',
company: '',
country: '',
firstName: '',
id: 'new',
lastName: '',
phone: '',
province: '',
zip: '',
} as AddressFragment;
return (
<AddressForm address={newAddress} defaultAddress={null}>
{({stateForMethod}) => (
<div>
<button
disabled={stateForMethod('POST') !== 'idle'}
formMethod="POST"
type="submit"
>
{stateForMethod('POST') !== 'idle' ? 'Creating' : 'Create'}
</button>
</div>
)}
</AddressForm>
);
}
function ExistingAddresses({
addresses,
defaultAddress,
}: Pick<CustomerFragment, 'addresses' | 'defaultAddress'>) {
return (
<div>
<legend>Existing addresses</legend>
{addresses.nodes.map((address) => (
<AddressForm
key={address.id}
address={address}
defaultAddress={defaultAddress}
>
{({stateForMethod}) => (
<div>
<button
disabled={stateForMethod('PUT') !== 'idle'}
formMethod="PUT"
type="submit"
>
{stateForMethod('PUT') !== 'idle' ? 'Saving' : 'Save'}
</button>
<button
disabled={stateForMethod('DELETE') !== 'idle'}
formMethod="DELETE"
type="submit"
>
{stateForMethod('DELETE') !== 'idle' ? 'Deleting' : 'Delete'}
</button>
</div>
)}
</AddressForm>
))}
</div>
);
}
export function AddressForm({
address,
defaultAddress,
children,
}: {
children: (props: {
stateForMethod: (
method: 'PUT' | 'POST' | 'DELETE',
) => ReturnType<typeof useNavigation>['state'];
}) => React.ReactNode;
defaultAddress: CustomerFragment['defaultAddress'];
address: AddressFragment;
}) {
const {state, formMethod} = useNavigation();
const action = useActionData<ActionResponse>();
const error = action?.error?.[address.id];
const isDefaultAddress = defaultAddress?.id === address.id;
return (
<Form id={address.id}>
<fieldset>
<input type="hidden" name="addressId" defaultValue={address.id} />
<label htmlFor="firstName">First name*</label>
<input
aria-label="First name"
autoComplete="given-name"
defaultValue={address?.firstName ?? ''}
id="firstName"
name="firstName"
placeholder="First name"
required
type="text"
/>
<label htmlFor="lastName">Last name*</label>
<input
aria-label="Last name"
autoComplete="family-name"
defaultValue={address?.lastName ?? ''}
id="lastName"
name="lastName"
placeholder="Last name"
required
type="text"
/>
<label htmlFor="company">Company</label>
<input
aria-label="Company"
autoComplete="organization"
defaultValue={address?.company ?? ''}
id="company"
name="company"
placeholder="Company"
type="text"
/>
<label htmlFor="address1">Address line*</label>
<input
aria-label="Address line 1"
autoComplete="address-line1"
defaultValue={address?.address1 ?? ''}
id="address1"
name="address1"
placeholder="Address line 1*"
required
type="text"
/>
<label htmlFor="address2">Address line 2</label>
<input
aria-label="Address line 2"
autoComplete="address-line2"
defaultValue={address?.address2 ?? ''}
id="address2"
name="address2"
placeholder="Address line 2"
type="text"
/>
<label htmlFor="city">City*</label>
<input
aria-label="City"
autoComplete="address-level2"
defaultValue={address?.city ?? ''}
id="city"
name="city"
placeholder="City"
required
type="text"
/>
<label htmlFor="province">State / Province*</label>
<input
aria-label="State"
autoComplete="address-level1"
defaultValue={address?.province ?? ''}
id="province"
name="province"
placeholder="State / Province"
required
type="text"
/>
<label htmlFor="zip">Zip / Postal Code*</label>
<input
aria-label="Zip"
autoComplete="postal-code"
defaultValue={address?.zip ?? ''}
id="zip"
name="zip"
placeholder="Zip / Postal Code"
required
type="text"
/>
<label htmlFor="country">Country*</label>
<input
aria-label="Country"
autoComplete="country-name"
defaultValue={address?.country ?? ''}
id="country"
name="country"
placeholder="Country"
required
type="text"
/>
<label htmlFor="phone">Phone</label>
<input
aria-label="Phone"
autoComplete="tel"
defaultValue={address?.phone ?? ''}
id="phone"
name="phone"
placeholder="+16135551111"
pattern="^\+?[1-9]\d{3,14}$"
type="tel"
/>
<div>
<input
defaultChecked={isDefaultAddress}
id="defaultAddress"
name="defaultAddress"
type="checkbox"
/>
<label htmlFor="defaultAddress">Set as default address</label>
</div>
{error ? (
<p>
<mark>
<small>{error}</small>
</mark>
</p>
) : (
<br />
)}
{children({
stateForMethod: (method) => (formMethod === method ? state : 'idle'),
})}
</fieldset>
</Form>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/2023-04/mutations/customeraddressupdate
const UPDATE_ADDRESS_MUTATION = `#graphql
mutation customerAddressUpdate(
$address: MailingAddressInput!
$customerAccessToken: String!
$id: ID!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerAddressUpdate(
address: $address
customerAccessToken: $customerAccessToken
id: $id
) {
customerAddress {
id
}
customerUserErrors {
code
field
message
}
}
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customerAddressDelete
const DELETE_ADDRESS_MUTATION = `#graphql
mutation customerAddressDelete(
$customerAccessToken: String!,
$id: ID!,
$country: CountryCode,
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerAddressDelete(customerAccessToken: $customerAccessToken, id: $id) {
customerUserErrors {
code
field
message
}
deletedCustomerAddressId
}
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customerdefaultaddressupdate
const UPDATE_DEFAULT_ADDRESS_MUTATION = `#graphql
mutation customerDefaultAddressUpdate(
$addressId: ID!
$customerAccessToken: String!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerDefaultAddressUpdate(
addressId: $addressId
customerAccessToken: $customerAccessToken
) {
customer {
defaultAddress {
id
}
}
customerUserErrors {
code
field
message
}
}
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customeraddresscreate
const CREATE_ADDRESS_MUTATION = `#graphql
mutation customerAddressCreate(
$address: MailingAddressInput!
$customerAccessToken: String!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerAddressCreate(
address: $address
customerAccessToken: $customerAccessToken
) {
customerAddress {
id
}
customerUserErrors {
code
field
message
}
}
}
` as const;

View File

@@ -0,0 +1,309 @@
import {json, redirect, type LoaderArgs} from '@shopify/remix-oxygen';
import {Link, useLoaderData, type V2_MetaFunction} from '@remix-run/react';
import {Money, Image, flattenConnection} from '@shopify/hydrogen';
import type {OrderLineItemFullFragment} from 'storefrontapi.generated';
export const meta: V2_MetaFunction<typeof loader> = ({data}) => {
return [{title: `Order ${data?.order?.name}`}];
};
export async function loader({params, context}: LoaderArgs) {
const {session, storefront} = context;
if (!params.id) {
return redirect('/account/orders');
}
const orderId = atob(params.id);
const customerAccessToken = await session.get('customerAccessToken');
if (!customerAccessToken) {
return redirect('/account/login');
}
const {order} = await storefront.query(CUSTOMER_ORDER_QUERY, {
variables: {orderId},
});
if (!order || !('lineItems' in order)) {
throw new Response('Order not found', {status: 404});
}
const lineItems = flattenConnection(order.lineItems);
const discountApplications = flattenConnection(order.discountApplications);
const firstDiscount = discountApplications[0]?.value;
const discountValue =
firstDiscount?.__typename === 'MoneyV2' && firstDiscount;
const discountPercentage =
firstDiscount?.__typename === 'PricingPercentageValue' &&
firstDiscount?.percentage;
return json({
order,
lineItems,
discountValue,
discountPercentage,
});
}
export default function OrderRoute() {
const {order, lineItems, discountValue, discountPercentage} =
useLoaderData<typeof loader>();
return (
<div className="account-order">
<h2>Order {order.name}</h2>
<p>Placed on {new Date(order.processedAt!).toDateString()}</p>
<br />
<div>
<table>
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
{lineItems.map((lineItem, lineItemIndex) => (
// eslint-disable-next-line react/no-array-index-key
<OrderLineRow key={lineItemIndex} lineItem={lineItem} />
))}
</tbody>
<tfoot>
{((discountValue && discountValue.amount) ||
discountPercentage) && (
<tr>
<th scope="row" colSpan={3}>
<p>Discounts</p>
</th>
<th scope="row">
<p>Discounts</p>
</th>
<td>
{discountPercentage ? (
<span>-{discountPercentage}% OFF</span>
) : (
discountValue && <Money data={discountValue!} />
)}
</td>
</tr>
)}
<tr>
<th scope="row" colSpan={3}>
<p>Subtotal</p>
</th>
<th scope="row">
<p>Subtotal</p>
</th>
<td>
<Money data={order.subtotalPriceV2!} />
</td>
</tr>
<tr>
<th scope="row" colSpan={3}>
Tax
</th>
<th scope="row">
<p>Tax</p>
</th>
<td>
<Money data={order.totalTaxV2!} />
</td>
</tr>
<tr>
<th scope="row" colSpan={3}>
Total
</th>
<th scope="row">
<p>Total</p>
</th>
<td>
<Money data={order.totalPriceV2!} />
</td>
</tr>
</tfoot>
</table>
<div>
<h3>Shipping Address</h3>
{order?.shippingAddress ? (
<address>
<p>
{order.shippingAddress.firstName &&
order.shippingAddress.firstName + ' '}
{order.shippingAddress.lastName}
</p>
{order?.shippingAddress?.formatted ? (
order.shippingAddress.formatted.map((line: string) => (
<p key={line}>{line}</p>
))
) : (
<></>
)}
</address>
) : (
<p>No shipping address defined</p>
)}
<h3>Status</h3>
<div>
<p>{order.fulfillmentStatus}</p>
</div>
</div>
</div>
<br />
<p>
<a target="_blank" href={order.statusUrl} rel="noreferrer">
View Order Status
</a>
</p>
</div>
);
}
function OrderLineRow({lineItem}: {lineItem: OrderLineItemFullFragment}) {
return (
<tr key={lineItem.variant!.id}>
<td>
<div>
<Link to={`/products/${lineItem.variant!.product!.handle}`}>
{lineItem?.variant?.image && (
<div>
<Image data={lineItem.variant.image} width={96} height={96} />
</div>
)}
</Link>
<div>
<p>{lineItem.title}</p>
<small>{lineItem.variant!.title}</small>
</div>
</div>
</td>
<td>
<Money data={lineItem.variant!.price!} />
</td>
<td>{lineItem.quantity}</td>
<td>
<Money data={lineItem.discountedTotalPrice!} />
</td>
</tr>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/objects/Order
const CUSTOMER_ORDER_QUERY = `#graphql
fragment OrderMoney on MoneyV2 {
amount
currencyCode
}
fragment AddressFull on MailingAddress {
address1
address2
city
company
country
countryCodeV2
firstName
formatted
id
lastName
name
phone
province
provinceCode
zip
}
fragment DiscountApplication on DiscountApplication {
value {
__typename
... on MoneyV2 {
...OrderMoney
}
... on PricingPercentageValue {
percentage
}
}
}
fragment OrderLineProductVariant on ProductVariant {
id
image {
altText
height
url
id
width
}
price {
...OrderMoney
}
product {
handle
}
sku
title
}
fragment OrderLineItemFull on OrderLineItem {
title
quantity
discountAllocations {
allocatedAmount {
...OrderMoney
}
discountApplication {
...DiscountApplication
}
}
originalTotalPrice {
...OrderMoney
}
discountedTotalPrice {
...OrderMoney
}
variant {
...OrderLineProductVariant
}
}
fragment Order on Order {
id
name
orderNumber
statusUrl
processedAt
fulfillmentStatus
totalTaxV2 {
...OrderMoney
}
totalPriceV2 {
...OrderMoney
}
subtotalPriceV2 {
...OrderMoney
}
shippingAddress {
...AddressFull
}
discountApplications(first: 100) {
nodes {
...DiscountApplication
}
}
lineItems(first: 100) {
nodes {
...OrderLineItemFull
}
}
}
query Order(
$country: CountryCode
$language: LanguageCode
$orderId: ID!
) @inContext(country: $country, language: $language) {
order: node(id: $orderId) {
... on Order {
...Order
}
}
}
` as const;

View File

@@ -0,0 +1,196 @@
import {Link, useLoaderData} from '@remix-run/react';
import {Money, Pagination, getPaginationVariables} from '@shopify/hydrogen';
import {
json,
redirect,
type LoaderArgs,
type V2_MetaFunction,
} from '@shopify/remix-oxygen';
import type {
CustomerOrdersFragment,
OrderItemFragment,
} from 'storefrontapi.generated';
export const meta: V2_MetaFunction = () => {
return [{title: 'Orders'}];
};
export async function loader({request, context}: LoaderArgs) {
const {session, storefront} = context;
const customerAccessToken = await session.get('customerAccessToken');
if (!customerAccessToken?.accessToken) {
return redirect('/account/login');
}
try {
const paginationVariables = getPaginationVariables(request, {
pageBy: 20,
});
const {customer} = await storefront.query(CUSTOMER_ORDERS_QUERY, {
variables: {
customerAccessToken: customerAccessToken.accessToken,
country: storefront.i18n.country,
language: storefront.i18n.language,
...paginationVariables,
},
cache: storefront.CacheNone(),
});
if (!customer) {
throw new Error('Customer not found');
}
return json({customer});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
}
export default function Orders() {
const {customer} = useLoaderData<{customer: CustomerOrdersFragment}>();
const {orders, numberOfOrders} = customer;
return (
<div className="orders">
<h2>
Orders <small>({numberOfOrders})</small>
</h2>
<br />
{orders.nodes.length ? <OrdersTable orders={orders} /> : <EmptyOrders />}
</div>
);
}
function OrdersTable({orders}: Pick<CustomerOrdersFragment, 'orders'>) {
return (
<div className="acccount-orders">
{orders?.nodes.length ? (
<Pagination connection={orders}>
{({nodes, isLoading, PreviousLink, NextLink}) => {
return (
<>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
{nodes.map((order) => {
return <OrderItem key={order.id} order={order} />;
})}
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</>
);
}}
</Pagination>
) : (
<EmptyOrders />
)}
</div>
);
}
function EmptyOrders() {
return (
<div>
<p>You haven&apos;t placed any orders yet.</p>
<br />
<p>
<Link to="/collections">Start Shopping </Link>
</p>
</div>
);
}
function OrderItem({order}: {order: OrderItemFragment}) {
return (
<>
<fieldset>
<Link to={`/account/orders/${order.id}`}>
<strong>#{order.orderNumber}</strong>
</Link>
<p>{new Date(order.processedAt).toDateString()}</p>
<p>{order.financialStatus}</p>
<p>{order.fulfillmentStatus}</p>
<Money data={order.currentTotalPrice} />
<Link to={`/account/orders/${btoa(order.id)}`}>View Order </Link>
</fieldset>
<br />
</>
);
}
const ORDER_ITEM_FRAGMENT = `#graphql
fragment OrderItem on Order {
currentTotalPrice {
amount
currencyCode
}
financialStatus
fulfillmentStatus
id
lineItems(first: 10) {
nodes {
title
variant {
image {
url
altText
height
width
}
}
}
}
orderNumber
customerUrl
statusUrl
processedAt
}
` as const;
export const CUSTOMER_FRAGMENT = `#graphql
fragment CustomerOrders on Customer {
numberOfOrders
orders(
sortKey: PROCESSED_AT,
reverse: true,
first: $first,
last: $last,
before: $startCursor,
after: $endCursor
) {
nodes {
...OrderItem
}
pageInfo {
hasPreviousPage
hasNextPage
hasNextPage
endCursor
}
}
}
${ORDER_ITEM_FRAGMENT}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/queries/customer
const CUSTOMER_ORDERS_QUERY = `#graphql
${CUSTOMER_FRAGMENT}
query CustomerOrders(
$country: CountryCode
$customerAccessToken: String!
$endCursor: String
$first: Int
$language: LanguageCode
$last: Int
$startCursor: String
) @inContext(country: $country, language: $language) {
customer(customerAccessToken: $customerAccessToken) {
...CustomerOrders
}
}
` as const;

View File

@@ -0,0 +1,289 @@
import type {CustomerFragment} from 'storefrontapi.generated';
import type {CustomerUpdateInput} from '@shopify/hydrogen/storefront-api-types';
import type {ActionArgs, LoaderArgs} from '@shopify/remix-oxygen';
import {json, redirect, type V2_MetaFunction} from '@shopify/remix-oxygen';
import {
Form,
useActionData,
useNavigation,
useOutletContext,
} from '@remix-run/react';
export type ActionResponse = {
error: string | null;
customer: CustomerFragment | null;
};
export const meta: V2_MetaFunction = () => {
return [{title: 'Profile'}];
};
export async function loader({context}: LoaderArgs) {
const customerAccessToken = await context.session.get('customerAccessToken');
if (!customerAccessToken) {
return redirect('/account/login');
}
return json({});
}
export async function action({request, context}: ActionArgs) {
const {session, storefront} = context;
if (request.method !== 'PUT') {
return json({error: 'Method not allowed'}, {status: 405});
}
const form = await request.formData();
const customerAccessToken = await session.get('customerAccessToken');
if (!customerAccessToken) {
return json({error: 'Unauthorized'}, {status: 401});
}
try {
const password = getPassword(form);
const customer: CustomerUpdateInput = {};
const validInputKeys = [
'firstName',
'lastName',
'email',
'password',
'phone',
] as const;
for (const [key, value] of form.entries()) {
if (!validInputKeys.includes(key as any)) {
continue;
}
if (key === 'acceptsMarketing') {
customer.acceptsMarketing = value === 'on';
}
if (typeof value === 'string' && value.length) {
customer[key as (typeof validInputKeys)[number]] = value;
}
}
if (password) {
customer.password = password;
}
// update customer and possibly password
const updated = await storefront.mutate(CUSTOMER_UPDATE_MUTATION, {
variables: {
customerAccessToken: customerAccessToken.accessToken,
customer,
},
});
// check for mutation errors
if (updated.customerUpdate?.customerUserErrors?.length) {
return json(
{error: updated.customerUpdate?.customerUserErrors[0]},
{status: 400},
);
}
// update session with the updated access token
if (updated.customerUpdate?.customerAccessToken?.accessToken) {
session.set(
'customerAccessToken',
updated.customerUpdate?.customerAccessToken,
);
}
return json(
{error: null, customer: updated.customerUpdate?.customer},
{
headers: {
'Set-Cookie': await session.commit(),
},
},
);
} catch (error: any) {
return json({error: error.message, customer: null}, {status: 400});
}
}
export default function AccountProfile() {
const account = useOutletContext<{customer: CustomerFragment}>();
const {state} = useNavigation();
const action = useActionData<ActionResponse>();
const customer = action?.customer ?? account?.customer;
return (
<div className="account-profile">
<h2>My profile</h2>
<br />
<Form method="PUT">
<legend>Personal information</legend>
<fieldset>
<label htmlFor="firstName">First name</label>
<input
id="firstName"
name="firstName"
type="text"
autoComplete="given-name"
placeholder="First name"
aria-label="First name"
defaultValue={customer.firstName ?? ''}
minLength={2}
/>
<label htmlFor="lastName">Last name</label>
<input
id="lastName"
name="lastName"
type="text"
autoComplete="family-name"
placeholder="Last name"
aria-label="Last name"
defaultValue={customer.lastName ?? ''}
minLength={2}
/>
<label htmlFor="phone">Mobile</label>
<input
id="phone"
name="phone"
type="tel"
autoComplete="tel"
placeholder="Mobile"
aria-label="Mobile"
defaultValue={customer.phone ?? ''}
/>
<label htmlFor="email">Email address</label>
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
placeholder="Email address"
aria-label="Email address"
defaultValue={customer.email ?? ''}
/>
<div className="account-profile-marketing">
<input
id="acceptsMarketing"
name="acceptsMarketing"
type="checkbox"
placeholder="Accept marketing"
aria-label="Accept marketing"
defaultChecked={customer.acceptsMarketing}
/>
<label htmlFor="acceptsMarketing">
&nbsp; Subscribed to marketing communications
</label>
</div>
</fieldset>
<br />
<legend>Change password (optional)</legend>
<fieldset>
<label htmlFor="currentPassword">Current password</label>
<input
id="currentPassword"
name="currentPassword"
type="password"
autoComplete="current-password"
placeholder="Current password"
aria-label="Current password"
minLength={8}
/>
<label htmlFor="newPassword">New password</label>
<input
id="newPassword"
name="newPassword"
type="password"
placeholder="New password"
aria-label="New password"
minLength={8}
/>
<label htmlFor="newPasswordConfirm">New password (confirm)</label>
<input
id="newPasswordConfirm"
name="newPasswordConfirm"
type="password"
placeholder="New password (confirm)"
aria-label="New password confirm"
minLength={8}
/>
<small>Passwords must be at least 8 characters.</small>
</fieldset>
{action?.error ? (
<p>
<mark>
<small>{action.error}</small>
</mark>
</p>
) : (
<br />
)}
<button type="submit" disabled={state !== 'idle'}>
{state !== 'idle' ? 'Updating' : 'Update'}
</button>
</Form>
</div>
);
}
function getPassword(form: FormData): string | undefined {
let password;
const currentPassword = form.get('currentPassword');
const newPassword = form.get('newPassword');
const newPasswordConfirm = form.get('newPasswordConfirm');
let passwordError;
if (newPassword && !currentPassword) {
passwordError = new Error('Current password is required.');
}
if (newPassword && newPassword !== newPasswordConfirm) {
passwordError = new Error('New passwords must match.');
}
if (newPassword && currentPassword && newPassword === currentPassword) {
passwordError = new Error(
'New password must be different than current password.',
);
}
if (passwordError) {
throw passwordError;
}
if (currentPassword && newPassword) {
password = newPassword;
} else {
password = currentPassword;
}
return String(password);
}
const CUSTOMER_UPDATE_MUTATION = `#graphql
# https://shopify.dev/docs/api/storefront/latest/mutations/customerUpdate
mutation customerUpdate(
$customerAccessToken: String!,
$customer: CustomerUpdateInput!
$country: CountryCode
$language: LanguageCode
) @inContext(language: $language, country: $country) {
customerUpdate(customerAccessToken: $customerAccessToken, customer: $customer) {
customer {
acceptsMarketing
email
firstName
id
lastName
phone
}
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
` as const;

View File

@@ -0,0 +1,203 @@
import {Form, NavLink, Outlet, useLoaderData} from '@remix-run/react';
import {json, redirect, type LoaderArgs} from '@shopify/remix-oxygen';
import type {CustomerFragment} from 'storefrontapi.generated';
export function shouldRevalidate() {
return true;
}
export async function loader({request, context}: LoaderArgs) {
const {session, storefront} = context;
const {pathname} = new URL(request.url);
const customerAccessToken = await session.get('customerAccessToken');
const isLoggedIn = Boolean(customerAccessToken?.accessToken);
const isAccountHome = pathname === '/account' || pathname === '/account/';
const isPrivateRoute =
/^\/account\/(orders|orders\/.*|profile|addresses|addresses\/.*)$/.test(
pathname,
);
if (!isLoggedIn) {
if (isPrivateRoute || isAccountHome) {
session.unset('customerAccessToken');
return redirect('/account/login', {
headers: {
'Set-Cookie': await session.commit(),
},
});
} else {
// public subroute such as /account/login...
return json({
isLoggedIn: false,
isAccountHome,
isPrivateRoute,
customer: null,
});
}
} else {
// loggedIn, default redirect to the orders page
if (isAccountHome) {
return redirect('/account/orders');
}
}
try {
const {customer} = await storefront.query(CUSTOMER_QUERY, {
variables: {
customerAccessToken: customerAccessToken.accessToken,
country: storefront.i18n.country,
language: storefront.i18n.language,
},
cache: storefront.CacheNone(),
});
if (!customer) {
throw new Error('Customer not found');
}
return json(
{isLoggedIn, isPrivateRoute, isAccountHome, customer},
{
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
},
},
);
} catch (error) {
// eslint-disable-next-line no-console
console.error('There was a problem loading account', error);
session.unset('customerAccessToken');
return redirect('/account/login', {
headers: {
'Set-Cookie': await session.commit(),
},
});
}
}
export default function Acccount() {
const {customer, isPrivateRoute, isAccountHome} =
useLoaderData<typeof loader>();
if (!isPrivateRoute && !isAccountHome) {
return <Outlet context={{customer}} />;
}
return (
<AccountLayout customer={customer as CustomerFragment}>
<br />
<br />
<Outlet context={{customer}} />
</AccountLayout>
);
}
function AccountLayout({
customer,
children,
}: {
customer: CustomerFragment;
children: React.ReactNode;
}) {
const heading = customer
? customer.firstName
? `Welcome, ${customer.firstName}`
: `Welcome to your account.`
: 'Account Details';
return (
<div className="account">
<h1>{heading}</h1>
<br />
<AcccountMenu />
{children}
</div>
);
}
function AcccountMenu() {
function isActiveStyle({
isActive,
isPending,
}: {
isActive: boolean;
isPending: boolean;
}) {
return {
fontWeight: isActive ? 'bold' : '',
color: isPending ? 'grey' : 'black',
};
}
return (
<nav role="navigation">
<NavLink to="/account/orders" style={isActiveStyle}>
Orders &nbsp;
</NavLink>
&nbsp;|&nbsp;
<NavLink to="/account/profile" style={isActiveStyle}>
&nbsp; Profile &nbsp;
</NavLink>
&nbsp;|&nbsp;
<NavLink to="/account/addresses" style={isActiveStyle}>
&nbsp; Addresses &nbsp;
</NavLink>
&nbsp;|&nbsp;
<Logout />
</nav>
);
}
function Logout() {
return (
<Form className="account-logout" method="POST" action="/account/logout">
&nbsp;<button type="submit">Sign out</button>
</Form>
);
}
export const CUSTOMER_FRAGMENT = `#graphql
fragment Customer on Customer {
acceptsMarketing
addresses(first: 6) {
nodes {
...Address
}
}
defaultAddress {
...Address
}
email
firstName
lastName
numberOfOrders
phone
}
fragment Address on MailingAddress {
id
formatted
firstName
lastName
company
address1
address2
country
province
city
zip
phone
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/queries/customer
const CUSTOMER_QUERY = `#graphql
query Customer(
$customerAccessToken: String!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customer(customerAccessToken: $customerAccessToken) {
...Customer
}
}
${CUSTOMER_FRAGMENT}
` as const;

View File

@@ -0,0 +1,157 @@
import type {ActionArgs, LoaderArgs} from '@shopify/remix-oxygen';
import {json, redirect} from '@shopify/remix-oxygen';
import {Form, useActionData, type V2_MetaFunction} from '@remix-run/react';
type ActionResponse = {
error: string | null;
};
export const meta: V2_MetaFunction = () => {
return [{title: 'Activate Account'}];
};
export async function loader({context}: LoaderArgs) {
if (await context.session.get('customerAccessToken')) {
return redirect('/account');
}
return json({});
}
export async function action({request, context, params}: ActionArgs) {
const {session, storefront} = context;
const {id, activationToken} = params;
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
try {
if (!id || !activationToken) {
throw new Error('Missing token. The link you followed might be wrong.');
}
const form = await request.formData();
const password = form.has('password') ? String(form.get('password')) : null;
const passwordConfirm = form.has('passwordConfirm')
? String(form.get('passwordConfirm'))
: null;
const validPasswords =
password && passwordConfirm && password === passwordConfirm;
if (!validPasswords) {
throw new Error('Passwords do not match');
}
const {customerActivate} = await storefront.mutate(
CUSTOMER_ACTIVATE_MUTATION,
{
variables: {
id: `gid://shopify/Customer/${id}`,
input: {
password,
activationToken,
},
},
},
);
if (customerActivate?.customerUserErrors?.length) {
throw new Error(customerActivate.customerUserErrors[0].message);
}
const {customerAccessToken} = customerActivate ?? {};
if (!customerAccessToken) {
throw new Error('Could not activate account.');
}
session.set('customerAccessToken', customerAccessToken);
return redirect('/account', {
headers: {
'Set-Cookie': await session.commit(),
},
});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
}
export default function Activate() {
const action = useActionData<ActionResponse>();
const error = action?.error ?? null;
return (
<div className="account-activate">
<h1>Activate Account.</h1>
<p>Create your password to activate your account.</p>
<Form method="POST">
<fieldset>
<label htmlFor="password">Password</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
placeholder="Password"
aria-label="Password"
minLength={8}
required
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
/>
<label htmlFor="passwordConfirm">Re-enter password</label>
<input
id="passwordConfirm"
name="passwordConfirm"
type="password"
autoComplete="current-password"
placeholder="Re-enter password"
aria-label="Re-enter password"
minLength={8}
required
/>
</fieldset>
{error ? (
<p>
<mark>
<small>{error}</small>
</mark>
</p>
) : (
<br />
)}
<button
className="bg-primary text-contrast rounded py-2 px-4 focus:shadow-outline block w-full"
type="submit"
>
Save
</button>
</Form>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customeractivate
const CUSTOMER_ACTIVATE_MUTATION = `#graphql
mutation customerActivate(
$id: ID!,
$input: CustomerActivateInput!,
$country: CountryCode,
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerActivate(id: $id, input: $input) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
` as const;

View File

@@ -0,0 +1,143 @@
import {
json,
redirect,
type ActionArgs,
type LoaderArgs,
type V2_MetaFunction,
} from '@shopify/remix-oxygen';
import {Form, Link, useActionData} from '@remix-run/react';
type ActionResponse = {
error: string | null;
};
export const meta: V2_MetaFunction = () => {
return [{title: 'Login'}];
};
export async function loader({context}: LoaderArgs) {
if (await context.session.get('customerAccessToken')) {
return redirect('/account');
}
return json({});
}
export async function action({request, context}: ActionArgs) {
const {session, storefront} = context;
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
try {
const form = await request.formData();
const email = String(form.has('email') ? form.get('email') : '');
const password = String(form.has('password') ? form.get('password') : '');
const validInputs = Boolean(email && password);
if (!validInputs) {
throw new Error('Please provide both an email and a password.');
}
const {customerAccessTokenCreate} = await storefront.mutate(
LOGIN_MUTATION,
{
variables: {
input: {email, password},
},
},
);
if (!customerAccessTokenCreate?.customerAccessToken?.accessToken) {
throw new Error(customerAccessTokenCreate?.customerUserErrors[0].message);
}
const {customerAccessToken} = customerAccessTokenCreate;
session.set('customerAccessToken', customerAccessToken);
return redirect('/account', {
headers: {
'Set-Cookie': await session.commit(),
},
});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
}
export default function Login() {
const data = useActionData<ActionResponse>();
const error = data?.error || null;
return (
<div className="login">
<h1>Sign in.</h1>
<Form method="POST">
<fieldset>
<label htmlFor="email">Email address</label>
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
placeholder="Email address"
aria-label="Email address"
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
/>
<label htmlFor="password">Password</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
placeholder="Password"
aria-label="Password"
minLength={8}
required
/>
</fieldset>
{error ? (
<p>
<mark>
<small>{error}</small>
</mark>
</p>
) : (
<br />
)}
<button type="submit">Sign in</button>
</Form>
<br />
<div>
<p>
<Link to="/account/recover">Forgot password </Link>
</p>
<p>
<Link to="/account/register">Register </Link>
</p>
</div>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customeraccesstokencreate
const LOGIN_MUTATION = `#graphql
mutation login($input: CustomerAccessTokenCreateInput!) {
customerAccessTokenCreate(input: $input) {
customerUserErrors {
code
field
message
}
customerAccessToken {
accessToken
expiresAt
}
}
}
` as const;

View File

@@ -0,0 +1,33 @@
import {
json,
redirect,
type ActionArgs,
type V2_MetaFunction,
} from '@shopify/remix-oxygen';
export const meta: V2_MetaFunction = () => {
return [{title: 'Logout'}];
};
export async function loader() {
return redirect('/account/login');
}
export async function action({request, context}: ActionArgs) {
const {session} = context;
session.unset('customerAccessToken');
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
return redirect('/', {
headers: {
'Set-Cookie': await session.commit(),
},
});
}
export default function Logout() {
return null;
}

View File

@@ -0,0 +1,124 @@
import {json, redirect, type LoaderArgs} from '@shopify/remix-oxygen';
import {Form, Link, useActionData} from '@remix-run/react';
type ActionResponse = {
error?: string;
resetRequested?: boolean;
};
export async function loader({context}: LoaderArgs) {
const customerAccessToken = await context.session.get('customerAccessToken');
if (customerAccessToken) {
return redirect('/account');
}
return json({});
}
export async function action({request, context}: LoaderArgs) {
const {storefront} = context;
const form = await request.formData();
const email = form.has('email') ? String(form.get('email')) : null;
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
try {
if (!email) {
throw new Error('Please provide an email.');
}
await storefront.mutate(CUSTOMER_RECOVER_MUTATION, {
variables: {email},
});
return json({resetRequested: true});
} catch (error: unknown) {
const resetRequested = false;
if (error instanceof Error) {
return json({error: error.message, resetRequested}, {status: 400});
}
return json({error, resetRequested}, {status: 400});
}
}
export default function Recover() {
const action = useActionData<ActionResponse>();
return (
<div className="account-recover">
<div>
{action?.resetRequested ? (
<>
<h1>Request Sent.</h1>
<p>
If that email address is in our system, you will receive an email
with instructions about how to reset your password in a few
minutes.
</p>
<br />
<Link to="/account/login">Return to Login</Link>
</>
) : (
<>
<h1>Forgot Password.</h1>
<p>
Enter the email address associated with your account to receive a
link to reset your password.
</p>
<br />
<Form method="POST">
<fieldset>
<label htmlFor="email">Email</label>
<input
aria-label="Email address"
autoComplete="email"
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
id="email"
name="email"
placeholder="Email address"
required
type="email"
/>
</fieldset>
{action?.error ? (
<p>
<mark>
<small>{action.error}</small>
</mark>
</p>
) : (
<br />
)}
<button type="submit">Request Reset Link</button>
</Form>
<div>
<br />
<p>
<Link to="/account/login">Login </Link>
</p>
</div>
</>
)}
</div>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customerrecover
const CUSTOMER_RECOVER_MUTATION = `#graphql
mutation customerRecover(
$email: String!,
$country: CountryCode,
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerRecover(email: $email) {
customerUserErrors {
code
field
message
}
}
}
` as const;

View File

@@ -0,0 +1,207 @@
import {
json,
redirect,
type ActionFunction,
type LoaderArgs,
} from '@shopify/remix-oxygen';
import {Form, Link, useActionData} from '@remix-run/react';
import type {CustomerCreateMutation} from 'storefrontapi.generated';
type ActionResponse = {
error: string | null;
newCustomer:
| NonNullable<CustomerCreateMutation['customerCreate']>['customer']
| null;
};
export async function loader({context}: LoaderArgs) {
const customerAccessToken = await context.session.get('customerAccessToken');
if (customerAccessToken) {
return redirect('/account');
}
return json({});
}
export const action: ActionFunction = async ({request, context}) => {
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
const {storefront, session} = context;
const form = await request.formData();
const email = String(form.has('email') ? form.get('email') : '');
const password = form.has('password') ? String(form.get('password')) : null;
const passwordConfirm = form.has('passwordConfirm')
? String(form.get('passwordConfirm'))
: null;
const validPasswords =
password && passwordConfirm && password === passwordConfirm;
const validInputs = Boolean(email && password);
try {
if (!validPasswords) {
throw new Error('Passwords do not match');
}
if (!validInputs) {
throw new Error('Please provide both an email and a password.');
}
const {customerCreate} = await storefront.mutate(CUSTOMER_CREATE_MUTATION, {
variables: {
input: {email, password},
},
});
if (customerCreate?.customerUserErrors?.length) {
throw new Error(customerCreate?.customerUserErrors[0].message);
}
const newCustomer = customerCreate?.customer;
if (!newCustomer?.id) {
throw new Error('Could not create customer');
}
// get an access token for the new customer
const {customerAccessTokenCreate} = await storefront.mutate(
REGISTER_LOGIN_MUTATION,
{
variables: {
input: {
email,
password,
},
},
},
);
if (!customerAccessTokenCreate?.customerAccessToken?.accessToken) {
throw new Error('Missing access token');
}
session.set(
'customerAccessToken',
customerAccessTokenCreate?.customerAccessToken,
);
return json(
{error: null, newCustomer},
{
status: 302,
headers: {
'Set-Cookie': await session.commit(),
Location: '/account',
},
},
);
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
};
export default function Register() {
const data = useActionData<ActionResponse>();
const error = data?.error || null;
return (
<div className="login">
<h1>Register.</h1>
<Form method="POST">
<fieldset>
<label htmlFor="email">Email address</label>
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
placeholder="Email address"
aria-label="Email address"
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
/>
<label htmlFor="password">Password</label>
<input
id="password"
name="password"
type="password"
autoComplete="current-password"
placeholder="Password"
aria-label="Password"
minLength={8}
required
/>
<label htmlFor="passwordConfirm">Re-enter password</label>
<input
id="passwordConfirm"
name="passwordConfirm"
type="password"
autoComplete="current-password"
placeholder="Re-enter password"
aria-label="Re-enter password"
minLength={8}
required
/>
</fieldset>
{error ? (
<p>
<mark>
<small>{error}</small>
</mark>
</p>
) : (
<br />
)}
<button type="submit">Register</button>
</Form>
<br />
<p>
<Link to="/account/login">Login </Link>
</p>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customerCreate
const CUSTOMER_CREATE_MUTATION = `#graphql
mutation customerCreate(
$input: CustomerCreateInput!,
$country: CountryCode,
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerCreate(input: $input) {
customer {
id
}
customerUserErrors {
code
field
message
}
}
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customeraccesstokencreate
const REGISTER_LOGIN_MUTATION = `#graphql
mutation registerLogin(
$input: CustomerAccessTokenCreateInput!,
$country: CountryCode,
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerAccessTokenCreate(input: $input) {
customerUserErrors {
code
field
message
}
customerAccessToken {
accessToken
expiresAt
}
}
}
` as const;

View File

@@ -0,0 +1,136 @@
import {type ActionArgs, json, redirect} from '@shopify/remix-oxygen';
import {Form, useActionData, type V2_MetaFunction} from '@remix-run/react';
type ActionResponse = {
error: string | null;
};
export const meta: V2_MetaFunction = () => {
return [{title: 'Reset Password'}];
};
export async function action({request, context, params}: ActionArgs) {
if (request.method !== 'POST') {
return json({error: 'Method not allowed'}, {status: 405});
}
const {id, resetToken} = params;
const {session, storefront} = context;
try {
if (!id || !resetToken) {
throw new Error('customer token or id not found');
}
const form = await request.formData();
const password = form.has('password') ? String(form.get('password')) : '';
const passwordConfirm = form.has('passwordConfirm')
? String(form.get('passwordConfirm'))
: '';
const validInputs = Boolean(password && passwordConfirm);
if (validInputs && password !== passwordConfirm) {
throw new Error('Please provide matching passwords');
}
const {customerReset} = await storefront.mutate(CUSTOMER_RESET_MUTATION, {
variables: {
id: `gid://shopify/Customer/${id}`,
input: {password, resetToken},
},
});
if (customerReset?.customerUserErrors?.length) {
throw new Error(customerReset?.customerUserErrors[0].message);
}
if (!customerReset?.customerAccessToken) {
throw new Error('Access token not found. Please try again.');
}
session.set('customerAccessToken', customerReset.customerAccessToken);
return redirect('/account', {
headers: {
'Set-Cookie': await session.commit(),
},
});
} catch (error: unknown) {
if (error instanceof Error) {
return json({error: error.message}, {status: 400});
}
return json({error}, {status: 400});
}
}
export default function Reset() {
const action = useActionData<ActionResponse>();
return (
<div className="account-reset">
<h1>Reset Password.</h1>
<p>Enter a new password for your account.</p>
<Form method="POST">
<fieldset>
<label htmlFor="password">Password</label>
<input
aria-label="Password"
autoComplete="current-password"
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
id="password"
minLength={8}
name="password"
placeholder="Password"
required
type="password"
/>
<label htmlFor="passwordConfirm">Re-enter password</label>
<input
aria-label="Re-enter password"
autoComplete="current-password"
id="passwordConfirm"
minLength={8}
name="passwordConfirm"
placeholder="Re-enter password"
required
type="password"
/>
</fieldset>
{action?.error ? (
<p>
<mark>
<small>{action.error}</small>
</mark>
</p>
) : (
<br />
)}
<button type="submit">Reset</button>
</Form>
<br />
<p>
<a href="/account/login">Back to login </a>
</p>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/mutations/customerreset
const CUSTOMER_RESET_MUTATION = `#graphql
mutation customerReset(
$id: ID!,
$input: CustomerResetInput!
$country: CountryCode
$language: LanguageCode
) @inContext(country: $country, language: $language) {
customerReset(id: $id, input: $input) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
` as const;

View File

@@ -0,0 +1,342 @@
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import type {
NormalizedPredictiveSearch,
NormalizedPredictiveSearchResults,
} from '~/components/Search';
import {NO_PREDICTIVE_SEARCH_RESULTS} from '~/components/Search';
import type {
PredictiveArticleFragment,
PredictiveCollectionFragment,
PredictivePageFragment,
PredictiveProductFragment,
PredictiveQueryFragment,
PredictiveSearchQuery,
} from 'storefrontapi.generated';
type PredictiveSearchResultItem =
| PredictiveArticleFragment
| PredictiveCollectionFragment
| PredictivePageFragment
| PredictiveProductFragment;
type PredictiveSearchTypes =
| 'ARTICLE'
| 'COLLECTION'
| 'PAGE'
| 'PRODUCT'
| 'QUERY';
const DEFAULT_SEARCH_TYPES: PredictiveSearchTypes[] = [
'ARTICLE',
'COLLECTION',
'PAGE',
'PRODUCT',
'QUERY',
];
/**
* Fetches the search results from the predictive search API
* requested by the SearchForm component
*/
export async function action({request, params, context}: LoaderArgs) {
if (request.method !== 'POST') {
throw new Error('Invalid request method');
}
const search = await fetchPredictiveSearchResults({
params,
request,
context,
});
return json(search);
}
async function fetchPredictiveSearchResults({
params,
request,
context,
}: Pick<LoaderArgs, 'params' | 'context' | 'request'>) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
let body;
try {
body = await request.formData();
} catch (error) {}
const searchTerm = String(body?.get('q') || searchParams.get('q') || '');
const limit = Number(body?.get('limit') || searchParams.get('limit') || 10);
const rawTypes = String(
body?.get('type') || searchParams.get('type') || 'ANY',
);
const searchTypes =
rawTypes === 'ANY'
? DEFAULT_SEARCH_TYPES
: rawTypes
.split(',')
.map((t) => t.toUpperCase() as PredictiveSearchTypes)
.filter((t) => DEFAULT_SEARCH_TYPES.includes(t));
if (!searchTerm) {
return {
searchResults: {results: null, totalResults: 0},
searchTerm,
searchTypes,
};
}
const data = await context.storefront.query(PREDICTIVE_SEARCH_QUERY, {
variables: {
limit,
limitScope: 'EACH',
searchTerm,
types: searchTypes,
},
});
if (!data) {
throw new Error('No data returned from Shopify API');
}
const searchResults = normalizePredictiveSearchResults(
data.predictiveSearch,
params.locale,
);
return {searchResults, searchTerm, searchTypes};
}
/**
* Normalize results and apply tracking qurery parameters to each result url
* @param predictiveSearch
* @param locale
*/
export function normalizePredictiveSearchResults(
predictiveSearch: PredictiveSearchQuery['predictiveSearch'],
locale: LoaderArgs['params']['locale'],
): NormalizedPredictiveSearch {
let totalResults = 0;
if (!predictiveSearch) {
return {
results: NO_PREDICTIVE_SEARCH_RESULTS,
totalResults,
};
}
function applyTrackingParams(
resource: PredictiveSearchResultItem | PredictiveQueryFragment,
params?: string,
) {
if (params) {
return resource.trackingParameters
? `?${params}&${resource.trackingParameters}`
: `?${params}`;
} else {
return resource.trackingParameters
? `?${resource.trackingParameters}`
: '';
}
}
const localePrefix = locale ? `/${locale}` : '';
const results: NormalizedPredictiveSearchResults = [];
if (predictiveSearch.queries.length) {
results.push({
type: 'queries',
items: predictiveSearch.queries.map((query: PredictiveQueryFragment) => {
const trackingParams = applyTrackingParams(
query,
`q=${encodeURIComponent(query.text)}`,
);
totalResults++;
return {
__typename: query.__typename,
handle: '',
id: query.text,
image: undefined,
title: query.text,
styledTitle: query.styledText,
url: `${localePrefix}/search${trackingParams}`,
};
}),
});
}
if (predictiveSearch.products.length) {
results.push({
type: 'products',
items: predictiveSearch.products.map(
(product: PredictiveProductFragment) => {
totalResults++;
const trackingParams = applyTrackingParams(product);
return {
__typename: product.__typename,
handle: product.handle,
id: product.id,
image: product.variants?.nodes?.[0]?.image,
title: product.title,
url: `${localePrefix}/products/${product.handle}${trackingParams}`,
price: product.variants.nodes[0].price,
};
},
),
});
}
if (predictiveSearch.collections.length) {
results.push({
type: 'collections',
items: predictiveSearch.collections.map(
(collection: PredictiveCollectionFragment) => {
totalResults++;
const trackingParams = applyTrackingParams(collection);
return {
__typename: collection.__typename,
handle: collection.handle,
id: collection.id,
image: collection.image,
title: collection.title,
url: `${localePrefix}/collections/${collection.handle}${trackingParams}`,
};
},
),
});
}
if (predictiveSearch.pages.length) {
results.push({
type: 'pages',
items: predictiveSearch.pages.map((page: PredictivePageFragment) => {
totalResults++;
const trackingParams = applyTrackingParams(page);
return {
__typename: page.__typename,
handle: page.handle,
id: page.id,
image: undefined,
title: page.title,
url: `${localePrefix}/pages/${page.handle}${trackingParams}`,
};
}),
});
}
if (predictiveSearch.articles.length) {
results.push({
type: 'articles',
items: predictiveSearch.articles.map(
(article: PredictiveArticleFragment) => {
totalResults++;
const trackingParams = applyTrackingParams(article);
return {
__typename: article.__typename,
handle: article.handle,
id: article.id,
image: article.image,
title: article.title,
url: `${localePrefix}/blog/${article.handle}${trackingParams}`,
};
},
),
});
}
return {results, totalResults};
}
const PREDICTIVE_SEARCH_QUERY = `#graphql
fragment PredictiveArticle on Article {
__typename
id
title
handle
image {
url
altText
width
height
}
trackingParameters
}
fragment PredictiveCollection on Collection {
__typename
id
title
handle
image {
url
altText
width
height
}
trackingParameters
}
fragment PredictivePage on Page {
__typename
id
title
handle
trackingParameters
}
fragment PredictiveProduct on Product {
__typename
id
title
handle
trackingParameters
variants(first: 1) {
nodes {
id
image {
url
altText
width
height
}
price {
amount
currencyCode
}
}
}
}
fragment PredictiveQuery on SearchQuerySuggestion {
__typename
text
styledText
trackingParameters
}
query predictiveSearch(
$country: CountryCode
$language: LanguageCode
$limit: Int!
$limitScope: PredictiveSearchLimitScope!
$searchTerm: String!
$types: [PredictiveSearchType!]
) @inContext(country: $country, language: $language) {
predictiveSearch(
limit: $limit,
limitScope: $limitScope,
query: $searchTerm,
types: $types,
) {
articles {
...PredictiveArticle
}
collections {
...PredictiveCollection
}
pages {
...PredictivePage
}
products {
...PredictiveProduct
}
queries {
...PredictiveQuery
}
}
}
` as const;

View File

@@ -0,0 +1,88 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {useLoaderData} from '@remix-run/react';
import {Image} from '@shopify/hydrogen';
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.article.title} article`}];
};
export async function loader({params, context}: LoaderArgs) {
const {blogHandle, articleHandle} = params;
if (!articleHandle || !blogHandle) {
throw new Response('Not found', {status: 404});
}
const {blog} = await context.storefront.query(ARTICLE_QUERY, {
variables: {blogHandle, articleHandle},
});
if (!blog?.articleByHandle) {
throw new Response(null, {status: 404});
}
const article = blog.articleByHandle;
return json({article});
}
export default function Article() {
const {article} = useLoaderData<typeof loader>();
const {title, image, contentHtml, author} = article;
const publishedDate = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(new Date(article.publishedAt));
return (
<div className="article">
<h1>
{title}
<span>
{publishedDate} &middot; {author?.name}
</span>
</h1>
{image && <Image data={image} sizes="90vw" loading="eager" />}
<div
dangerouslySetInnerHTML={{__html: contentHtml}}
className="article"
/>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/objects/blog#field-blog-articlebyhandle
const ARTICLE_QUERY = `#graphql
query Article(
$articleHandle: String!
$blogHandle: String!
$country: CountryCode
$language: LanguageCode
) @inContext(language: $language, country: $country) {
blog(handle: $blogHandle) {
articleByHandle(handle: $articleHandle) {
title
contentHtml
publishedAt
author: authorV2 {
name
}
image {
id
altText
url
width
height
}
seo {
description
title
}
}
}
}
` as const;

View File

@@ -0,0 +1,162 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {Link, useLoaderData} from '@remix-run/react';
import {Image, Pagination, getPaginationVariables} from '@shopify/hydrogen';
import type {ArticleItemFragment} from 'storefrontapi.generated';
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.blog.title} blog`}];
};
export const loader = async ({
request,
params,
context: {storefront},
}: LoaderArgs) => {
const paginationVariables = getPaginationVariables(request, {
pageBy: 4,
});
if (!params.blogHandle) {
throw new Response(`blog not found`, {status: 404});
}
const {blog} = await storefront.query(BLOGS_QUERY, {
variables: {
blogHandle: params.blogHandle,
...paginationVariables,
},
});
if (!blog?.articles) {
throw new Response('Not found', {status: 404});
}
return json({blog});
};
export default function Blog() {
const {blog} = useLoaderData<typeof loader>();
const {articles} = blog;
return (
<div className="blog">
<h1>{blog.title}</h1>
<div className="blog-grid">
<Pagination connection={articles}>
{({nodes, isLoading, PreviousLink, NextLink}) => {
return (
<>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
{nodes.map((article, index) => {
return (
<ArticleItem
article={article}
key={article.id}
loading={index < 2 ? 'eager' : 'lazy'}
/>
);
})}
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</>
);
}}
</Pagination>
</div>
</div>
);
}
function ArticleItem({
article,
loading,
}: {
article: ArticleItemFragment;
loading?: HTMLImageElement['loading'];
}) {
const publishedAt = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(new Date(article.publishedAt!));
return (
<div className="blog-article" key={article.id}>
<Link to={`/blogs/${article.blog.handle}/${article.handle}`}>
{article.image && (
<div className="blog-article-image">
<Image
alt={article.image.altText || article.title}
aspectRatio="3/2"
data={article.image}
loading={loading}
sizes="(min-width: 768px) 50vw, 100vw"
/>
</div>
)}
<h3>{article.title}</h3>
<small>{publishedAt}</small>
</Link>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/objects/blog
const BLOGS_QUERY = `#graphql
query Blog(
$language: LanguageCode
$blogHandle: String!
$first: Int
$last: Int
$startCursor: String
$endCursor: String
) @inContext(language: $language) {
blog(handle: $blogHandle) {
title
seo {
title
description
}
articles(
first: $first,
last: $last,
before: $startCursor,
after: $endCursor
) {
nodes {
...ArticleItem
}
pageInfo {
hasPreviousPage
hasNextPage
hasNextPage
endCursor
}
}
}
}
fragment ArticleItem on Article {
author: authorV2 {
name
}
contentHtml
handle
id
image {
id
altText
url
width
height
}
publishedAt
title
blog {
handle
}
}
` as const;

View File

@@ -0,0 +1,94 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {Link, useLoaderData} from '@remix-run/react';
import {Pagination, getPaginationVariables} from '@shopify/hydrogen';
export const meta: V2_MetaFunction = () => {
return [{title: `Hydrogen | Logs`}];
};
export const loader = async ({request, context: {storefront}}: LoaderArgs) => {
const paginationVariables = getPaginationVariables(request, {
pageBy: 10,
});
const {blogs} = await storefront.query(BLOGS_QUERY, {
variables: {
...paginationVariables,
},
});
return json({blogs});
};
export default function Blogs() {
const {blogs} = useLoaderData<typeof loader>();
return (
<div className="blogs">
<h1>Blogs</h1>
<div className="blogs-grid">
<Pagination connection={blogs}>
{({nodes, isLoading, PreviousLink, NextLink}) => {
return (
<>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
{nodes.map((blog) => {
return (
<Link
className="blog"
key={blog.handle}
prefetch="intent"
to={`/blogs/${blog.handle}`}
>
<h2>{blog.title}</h2>
</Link>
);
})}
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</>
);
}}
</Pagination>
</div>
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/objects/blog
const BLOGS_QUERY = `#graphql
query Blogs(
$country: CountryCode
$endCursor: String
$first: Int
$language: LanguageCode
$last: Int
$startCursor: String
) @inContext(country: $country, language: $language) {
blogs(
first: $first,
last: $last,
before: $startCursor,
after: $endCursor
) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
nodes {
title
handle
seo {
title
description
}
}
}
}
` as const;

View File

@@ -0,0 +1,104 @@
import {Await, useMatches} from '@remix-run/react';
import {Suspense} from 'react';
import type {CartQueryData} from '@shopify/hydrogen';
import {CartForm} from '@shopify/hydrogen';
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {type ActionArgs, json} from '@shopify/remix-oxygen';
import type {CartApiQueryFragment} from 'storefrontapi.generated';
import {CartMain} from '~/components/Cart';
export const meta: V2_MetaFunction = () => {
return [{title: `Hydrogen | Cart`}];
};
export async function action({request, context}: ActionArgs) {
const {session, cart} = context;
const [formData, customerAccessToken] = await Promise.all([
request.formData(),
session.get('customerAccessToken'),
]);
const {action, inputs} = CartForm.getFormInput(formData);
if (!action) {
throw new Error('No action provided');
}
let status = 200;
let result: CartQueryData;
switch (action) {
case CartForm.ACTIONS.LinesAdd:
result = await cart.addLines(inputs.lines);
break;
case CartForm.ACTIONS.LinesUpdate:
result = await cart.updateLines(inputs.lines);
break;
case CartForm.ACTIONS.LinesRemove:
result = await cart.removeLines(inputs.lineIds);
break;
case CartForm.ACTIONS.DiscountCodesUpdate: {
const formDiscountCode = inputs.discountCode;
// User inputted discount code
const discountCodes = (
formDiscountCode ? [formDiscountCode] : []
) as string[];
// Combine discount codes already applied on cart
discountCodes.push(...inputs.discountCodes);
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
customerAccessToken,
});
break;
}
default:
throw new Error(`${action} cart action is not defined`);
}
const cartId = result.cart.id;
const headers = cart.setCartId(result.cart.id);
const {cart: cartResult, errors} = result;
const redirectTo = formData.get('redirectTo') ?? null;
if (typeof redirectTo === 'string') {
status = 303;
headers.set('Location', redirectTo);
}
return json(
{
cart: cartResult,
errors,
analytics: {
cartId,
},
},
{status, headers},
);
}
export default function Cart() {
const [root] = useMatches();
const cart = root.data?.cart as Promise<CartApiQueryFragment | null>;
return (
<div className="cart">
<h1>Cart</h1>
<Suspense fallback={<p>Loading cart ...</p>}>
<Await errorElement={<div>An error occurred</div>} resolve={cart}>
{(cart) => {
return <CartMain layout="page" cart={cart} />;
}}
</Await>
</Suspense>
</div>
);
}

View File

@@ -0,0 +1,184 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, redirect, type LoaderArgs} from '@shopify/remix-oxygen';
import {useLoaderData, Link} from '@remix-run/react';
import {
Pagination,
getPaginationVariables,
Image,
Money,
} from '@shopify/hydrogen';
import type {ProductItemFragment} from 'storefrontapi.generated';
import {useVariantUrl} from '~/utils';
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.collection.title} Collection`}];
};
export async function loader({request, params, context}: LoaderArgs) {
const {handle} = params;
const {storefront} = context;
const paginationVariables = getPaginationVariables(request, {
pageBy: 8,
});
if (!handle) {
return redirect('/collections');
}
const {collection} = await storefront.query(COLLECTION_QUERY, {
variables: {handle, ...paginationVariables},
});
if (!collection) {
throw new Response(`Collection ${handle} not found`, {
status: 404,
});
}
return json({collection});
}
export default function Collection() {
const {collection} = useLoaderData<typeof loader>();
return (
<div className="collection">
<h1>{collection.title}</h1>
<p className="collection-description">{collection.description}</p>
<Pagination connection={collection.products}>
{({nodes, isLoading, PreviousLink, NextLink}) => (
<>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
<ProductsGrid products={nodes} />
<br />
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</>
)}
</Pagination>
</div>
);
}
function ProductsGrid({products}: {products: ProductItemFragment[]}) {
return (
<div className="products-grid">
{products.map((product, index) => {
return (
<ProductItem
key={product.id}
product={product}
loading={index < 8 ? 'eager' : undefined}
/>
);
})}
</div>
);
}
function ProductItem({
product,
loading,
}: {
product: ProductItemFragment;
loading?: 'eager' | 'lazy';
}) {
const variant = product.variants.nodes[0];
const variantUrl = useVariantUrl(product.handle, variant.selectedOptions);
return (
<Link
className="product-item"
key={product.id}
prefetch="intent"
to={variantUrl}
>
{product.featuredImage && (
<Image
alt={product.featuredImage.altText || product.title}
aspectRatio="1/1"
data={product.featuredImage}
loading={loading}
sizes="(min-width: 45em) 400px, 100vw"
/>
)}
<h4>{product.title}</h4>
<small>
<Money data={product.priceRange.minVariantPrice} />
</small>
</Link>
);
}
const PRODUCT_ITEM_FRAGMENT = `#graphql
fragment MoneyProductItem on MoneyV2 {
amount
currencyCode
}
fragment ProductItem on Product {
id
handle
title
featuredImage {
id
altText
url
width
height
}
priceRange {
minVariantPrice {
...MoneyProductItem
}
maxVariantPrice {
...MoneyProductItem
}
}
variants(first: 1) {
nodes {
selectedOptions {
name
value
}
}
}
}
` as const;
// NOTE: https://shopify.dev/docs/api/storefront/2022-04/objects/collection
const COLLECTION_QUERY = `#graphql
${PRODUCT_ITEM_FRAGMENT}
query Collection(
$handle: String!
$country: CountryCode
$language: LanguageCode
$first: Int
$last: Int
$startCursor: String
$endCursor: String
) @inContext(country: $country, language: $language) {
collection(handle: $handle) {
id
handle
title
description
products(
first: $first,
last: $last,
before: $startCursor,
after: $endCursor
) {
nodes {
...ProductItem
}
pageInfo {
hasPreviousPage
hasNextPage
hasNextPage
endCursor
}
}
}
}
` as const;

View File

@@ -0,0 +1,120 @@
import {useLoaderData, Link} from '@remix-run/react';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {Pagination, getPaginationVariables, Image} from '@shopify/hydrogen';
import type {CollectionFragment} from 'storefrontapi.generated';
export async function loader({context, request}: LoaderArgs) {
const paginationVariables = getPaginationVariables(request, {
pageBy: 4,
});
const {collections} = await context.storefront.query(COLLECTIONS_QUERY, {
variables: paginationVariables,
});
return json({collections});
}
export default function Collections() {
const {collections} = useLoaderData<typeof loader>();
return (
<div className="collections">
<h1>Collections</h1>
<Pagination connection={collections}>
{({nodes, isLoading, PreviousLink, NextLink}) => (
<div>
<PreviousLink>
{isLoading ? 'Loading...' : <span> Load previous</span>}
</PreviousLink>
<CollectionsGrid collections={nodes} />
<NextLink>
{isLoading ? 'Loading...' : <span>Load more </span>}
</NextLink>
</div>
)}
</Pagination>
</div>
);
}
function CollectionsGrid({collections}: {collections: CollectionFragment[]}) {
return (
<div className="collections-grid">
{collections.map((collection, index) => (
<CollectionItem
key={collection.id}
collection={collection}
index={index}
/>
))}
</div>
);
}
function CollectionItem({
collection,
index,
}: {
collection: CollectionFragment;
index: number;
}) {
return (
<Link
className="collection-item"
key={collection.id}
to={`/collections/${collection.handle}`}
prefetch="intent"
>
{collection.image && (
<Image
alt={collection.image.altText || collection.title}
aspectRatio="1/1"
data={collection.image}
loading={index < 3 ? 'eager' : undefined}
/>
)}
<h5>{collection.title}</h5>
</Link>
);
}
const COLLECTIONS_QUERY = `#graphql
fragment Collection on Collection {
id
title
handle
image {
id
url
altText
width
height
}
}
query StoreCollections(
$country: CountryCode
$endCursor: String
$first: Int
$language: LanguageCode
$last: Int
$startCursor: String
) @inContext(country: $country, language: $language) {
collections(
first: $first,
last: $last,
before: $startCursor,
after: $endCursor
) {
nodes {
...Collection
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
` as const;

View File

@@ -0,0 +1,57 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {useLoaderData} from '@remix-run/react';
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.page.title}`}];
};
export async function loader({params, context}: LoaderArgs) {
if (!params.handle) {
throw new Error('Missing page handle');
}
const {page} = await context.storefront.query(PAGE_QUERY, {
variables: {
handle: params.handle,
},
});
if (!page) {
throw new Response('Not Found', {status: 404});
}
return json({page});
}
export default function Page() {
const {page} = useLoaderData<typeof loader>();
return (
<div className="page">
<header>
<h1>{page.title}</h1>
</header>
<main dangerouslySetInnerHTML={{__html: page.body}} />
</div>
);
}
const PAGE_QUERY = `#graphql
query Page(
$language: LanguageCode,
$country: CountryCode,
$handle: String!
)
@inContext(language: $language, country: $country) {
page(handle: $handle) {
id
title
body
seo {
description
title
}
}
}
` as const;

View File

@@ -0,0 +1,94 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {Link, useLoaderData} from '@remix-run/react';
import {type Shop} from '@shopify/hydrogen-react/storefront-api-types';
type SelectedPolicies = keyof Pick<
Shop,
'privacyPolicy' | 'shippingPolicy' | 'termsOfService' | 'refundPolicy'
>;
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.policy.title}`}];
};
export async function loader({params, context}: LoaderArgs) {
if (!params.handle) {
throw new Response('No handle was passed in', {status: 404});
}
const policyName = params.handle.replace(
/-([a-z])/g,
(_: unknown, m1: string) => m1.toUpperCase(),
) as SelectedPolicies;
const data = await context.storefront.query(POLICY_CONTENT_QUERY, {
variables: {
privacyPolicy: false,
shippingPolicy: false,
termsOfService: false,
refundPolicy: false,
[policyName]: true,
language: context.storefront.i18n?.language,
},
});
const policy = data.shop?.[policyName];
if (!policy) {
throw new Response('Could not find the policy', {status: 404});
}
return json({policy});
}
export default function Policy() {
const {policy} = useLoaderData<typeof loader>();
return (
<div className="policy">
<br />
<br />
<div>
<Link to="/policies"> Back to Policies</Link>
</div>
<br />
<h1>{policy.title}</h1>
<div dangerouslySetInnerHTML={{__html: policy.body}} />
</div>
);
}
// NOTE: https://shopify.dev/docs/api/storefront/latest/objects/Shop
const POLICY_CONTENT_QUERY = `#graphql
fragment Policy on ShopPolicy {
body
handle
id
title
url
}
query Policy(
$country: CountryCode
$language: LanguageCode
$privacyPolicy: Boolean!
$refundPolicy: Boolean!
$shippingPolicy: Boolean!
$termsOfService: Boolean!
) @inContext(language: $language, country: $country) {
shop {
privacyPolicy @include(if: $privacyPolicy) {
...Policy
}
shippingPolicy @include(if: $shippingPolicy) {
...Policy
}
termsOfService @include(if: $termsOfService) {
...Policy
}
refundPolicy @include(if: $refundPolicy) {
...Policy
}
}
}
` as const;

View File

@@ -0,0 +1,63 @@
import {json, type LoaderArgs} from '@shopify/remix-oxygen';
import {useLoaderData, Link} from '@remix-run/react';
export async function loader({context}: LoaderArgs) {
const data = await context.storefront.query(POLICIES_QUERY);
const policies = Object.values(data.shop || {});
if (!policies.length) {
throw new Response('No policies found', {status: 404});
}
return json({policies});
}
export default function Policies() {
const {policies} = useLoaderData<typeof loader>();
return (
<div className="policies">
<h1>Policies</h1>
<div>
{policies.map((policy) => {
if (!policy) return null;
return (
<fieldset key={policy.id}>
<Link to={`/policies/${policy.handle}`}>{policy.title}</Link>
</fieldset>
);
})}
</div>
</div>
);
}
const POLICIES_QUERY = `#graphql
fragment PolicyItem on ShopPolicy {
id
title
handle
}
query Policies ($country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
shop {
privacyPolicy {
...PolicyItem
}
shippingPolicy {
...PolicyItem
}
termsOfService {
...PolicyItem
}
refundPolicy {
...PolicyItem
}
subscriptionPolicy {
id
title
handle
}
}
}
` as const;

View File

@@ -0,0 +1,418 @@
import {Suspense} from 'react';
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {defer, redirect, type LoaderArgs} from '@shopify/remix-oxygen';
import type {FetcherWithComponents} from '@remix-run/react';
import {Await, Link, useLoaderData} from '@remix-run/react';
import type {
ProductFragment,
ProductVariantsQuery,
ProductVariantFragment,
} from 'storefrontapi.generated';
import {
Image,
Money,
VariantSelector,
type VariantOption,
getSelectedProductOptions,
CartForm,
} from '@shopify/hydrogen';
import type {CartLineInput} from '@shopify/hydrogen/storefront-api-types';
import {getVariantUrl} from '~/utils';
export const meta: V2_MetaFunction = ({data}) => {
return [{title: `Hydrogen | ${data.product.title}`}];
};
export async function loader({params, request, context}: LoaderArgs) {
const {handle} = params;
const {storefront} = context;
const selectedOptions = getSelectedProductOptions(request).filter(
(option) =>
// Filter out Shopify predictive search query params
!option.name.startsWith('_sid') &&
!option.name.startsWith('_pos') &&
!option.name.startsWith('_psq') &&
!option.name.startsWith('_ss') &&
!option.name.startsWith('_v'),
);
if (!handle) {
throw new Error('Expected product handle to be defined');
}
// await the query for the critical product data
const {product} = await storefront.query(PRODUCT_QUERY, {
variables: {handle, selectedOptions},
});
// In order to show which variants are available in the UI, we need to query
// all of them. But there might be a *lot*, so instead separate the variants
// into it's own separate query that is deferred. So there's a brief moment
// where variant options might show as available when they're not, but after
// this deffered query resolves, the UI will update.
const variants = storefront.query(VARIANTS_QUERY, {
variables: {handle},
});
if (!product?.id) {
throw new Response(null, {status: 404});
}
const firstVariant = product.variants.nodes[0];
const firstVariantIsDefault = Boolean(
firstVariant.selectedOptions.find(
(option) => option.name === 'Title' && option.value === 'Default Title',
),
);
if (firstVariantIsDefault) {
product.selectedVariant = firstVariant;
} else {
// if no selected variant was returned from the selected options,
// we redirect to the first variant's url with it's selected options applied
if (!product.selectedVariant) {
return redirectToFirstVariant({product, request});
}
}
return defer({product, variants});
}
function redirectToFirstVariant({
product,
request,
}: {
product: ProductFragment;
request: Request;
}) {
const url = new URL(request.url);
const firstVariant = product.variants.nodes[0];
throw redirect(
getVariantUrl({
pathname: url.pathname,
handle: product.handle,
selectedOptions: firstVariant.selectedOptions,
searchParams: new URLSearchParams(url.search),
}),
{
status: 302,
},
);
}
export default function Product() {
const {product, variants} = useLoaderData<typeof loader>();
const {selectedVariant} = product;
return (
<div className="product">
<ProductImage image={selectedVariant?.image} />
<ProductMain
selectedVariant={selectedVariant}
product={product}
variants={variants}
/>
</div>
);
}
function ProductImage({image}: {image: ProductVariantFragment['image']}) {
if (!image) {
return <div className="product-image" />;
}
return (
<div className="product-image">
<Image
alt={image.altText || 'Product Image'}
aspectRatio="1/1"
data={image}
key={image.id}
sizes="(min-width: 45em) 50vw, 100vw"
/>
</div>
);
}
function ProductMain({
selectedVariant,
product,
variants,
}: {
product: ProductFragment;
selectedVariant: ProductFragment['selectedVariant'];
variants: Promise<ProductVariantsQuery>;
}) {
const {title, descriptionHtml} = product;
return (
<div className="product-main">
<h1>{title}</h1>
<ProductPrice selectedVariant={selectedVariant} />
<br />
<Suspense
fallback={
<ProductForm
product={product}
selectedVariant={selectedVariant}
variants={[]}
/>
}
>
<Await
errorElement="There was a problem loading product variants"
resolve={variants}
>
{(data) => (
<ProductForm
product={product}
selectedVariant={selectedVariant}
variants={data.product?.variants.nodes || []}
/>
)}
</Await>
</Suspense>
<br />
<br />
<p>
<strong>Description</strong>
</p>
<br />
<div dangerouslySetInnerHTML={{__html: descriptionHtml}} />
<br />
</div>
);
}
function ProductPrice({
selectedVariant,
}: {
selectedVariant: ProductFragment['selectedVariant'];
}) {
return (
<div className="product-price">
{selectedVariant?.compareAtPrice ? (
<>
<p>Sale</p>
<br />
<div className="product-price-on-sale">
{selectedVariant ? <Money data={selectedVariant.price} /> : null}
<s>
<Money data={selectedVariant.compareAtPrice} />
</s>
</div>
</>
) : (
selectedVariant?.price && <Money data={selectedVariant?.price} />
)}
</div>
);
}
function ProductForm({
product,
selectedVariant,
variants,
}: {
product: ProductFragment;
selectedVariant: ProductFragment['selectedVariant'];
variants: Array<ProductVariantFragment>;
}) {
return (
<div className="product-form">
<VariantSelector
handle={product.handle}
options={product.options}
variants={variants}
>
{({option}) => <ProductOptions key={option.name} option={option} />}
</VariantSelector>
<br />
<AddToCartButton
disabled={!selectedVariant || !selectedVariant.availableForSale}
onClick={() => {
window.location.href = window.location.href + '#cart-aside';
}}
lines={
selectedVariant
? [
{
merchandiseId: selectedVariant.id,
quantity: 1,
},
]
: []
}
>
{selectedVariant?.availableForSale ? 'Add to cart' : 'Sold out'}
</AddToCartButton>
</div>
);
}
function ProductOptions({option}: {option: VariantOption}) {
return (
<div className="product-options" key={option.name}>
<h5>{option.name}</h5>
<div className="product-options-grid">
{option.values.map(({value, isAvailable, isActive, to}) => {
return (
<Link
className="product-options-item"
key={option.name + value}
prefetch="intent"
preventScrollReset
replace
to={to}
style={{
border: isActive ? '1px solid black' : '1px solid transparent',
opacity: isAvailable ? 1 : 0.3,
}}
>
{value}
</Link>
);
})}
</div>
<br />
</div>
);
}
function AddToCartButton({
analytics,
children,
disabled,
lines,
onClick,
}: {
analytics?: unknown;
children: React.ReactNode;
disabled?: boolean;
lines: CartLineInput[];
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>
);
}
const PRODUCT_VARIANT_FRAGMENT = `#graphql
fragment ProductVariant on ProductVariant {
availableForSale
compareAtPrice {
amount
currencyCode
}
id
image {
__typename
id
url
altText
width
height
}
price {
amount
currencyCode
}
product {
title
handle
}
quantityAvailable
selectedOptions {
name
value
}
sku
title
unitPrice {
amount
currencyCode
}
}
` as const;
const PRODUCT_FRAGMENT = `#graphql
fragment Product on Product {
id
title
vendor
handle
descriptionHtml
description
options {
name
values
}
selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions) {
...ProductVariant
}
variants(first: 1) {
nodes {
...ProductVariant
}
}
seo {
description
title
}
}
${PRODUCT_VARIANT_FRAGMENT}
` as const;
const PRODUCT_QUERY = `#graphql
query Product(
$country: CountryCode
$handle: String!
$language: LanguageCode
$selectedOptions: [SelectedOptionInput!]!
) @inContext(country: $country, language: $language) {
product(handle: $handle) {
...Product
}
}
${PRODUCT_FRAGMENT}
` as const;
const PRODUCT_VARIANTS_FRAGMENT = `#graphql
fragment ProductVariants on Product {
variants(first: 250) {
nodes {
...ProductVariant
}
}
}
${PRODUCT_VARIANT_FRAGMENT}
` as const;
const VARIANTS_QUERY = `#graphql
${PRODUCT_VARIANTS_FRAGMENT}
query ProductVariants(
$country: CountryCode
$language: LanguageCode
$handle: String!
) @inContext(country: $country, language: $language) {
product(handle: $handle) {
...ProductVariants
}
}
` as const;

View File

@@ -0,0 +1,168 @@
import type {V2_MetaFunction} from '@shopify/remix-oxygen';
import {defer, type LoaderArgs} from '@shopify/remix-oxygen';
import {useLoaderData} from '@remix-run/react';
import {getPaginationVariables} from '@shopify/hydrogen';
import {SearchForm, SearchResults, NoSearchResults} from '~/components/Search';
export const meta: V2_MetaFunction = () => {
return [{title: `Hydrogen | Search`}];
};
export async function loader({request, context}: LoaderArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const variables = getPaginationVariables(request, {pageBy: 8});
const searchTerm = String(searchParams.get('q') || '');
if (!searchTerm) {
return {
searchResults: {results: null, totalResults: 0},
searchTerm,
};
}
const data = await context.storefront.query(SEARCH_QUERY, {
variables: {
query: searchTerm,
...variables,
},
});
if (!data) {
throw new Error('No search data returned from Shopify API');
}
const totalResults = Object.values(data).reduce((total, value) => {
return total + value.nodes.length;
}, 0);
const searchResults = {
results: data,
totalResults,
};
return defer({searchTerm, searchResults});
}
export default function SearchPage() {
const {searchTerm, searchResults} = useLoaderData<typeof loader>();
return (
<div className="search">
<h1>Search</h1>
<SearchForm searchTerm={searchTerm} />
{!searchTerm || !searchResults.totalResults ? (
<NoSearchResults />
) : (
<SearchResults results={searchResults.results} />
)}
</div>
);
}
const SEARCH_QUERY = `#graphql
fragment SearchProduct on Product {
__typename
handle
id
publishedAt
title
trackingParameters
vendor
variants(first: 1) {
nodes {
id
image {
url
altText
width
height
}
price {
amount
currencyCode
}
compareAtPrice {
amount
currencyCode
}
selectedOptions {
name
value
}
product {
handle
title
}
}
}
}
fragment SearchPage on Page {
__typename
handle
id
title
trackingParameters
}
fragment SearchArticle on Article {
__typename
handle
id
title
trackingParameters
}
query search(
$country: CountryCode
$endCursor: String
$first: Int
$language: LanguageCode
$last: Int
$query: String!
$startCursor: String
) @inContext(country: $country, language: $language) {
products: search(
query: $query,
unavailableProducts: HIDE,
types: [PRODUCT],
first: $first,
sortKey: RELEVANCE,
last: $last,
before: $startCursor,
after: $endCursor
) {
nodes {
...on Product {
...SearchProduct
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
pages: search(
query: $query,
types: [PAGE],
first: 10
) {
nodes {
...on Page {
...SearchPage
}
}
}
articles: search(
query: $query,
types: [ARTICLE],
first: 10
) {
nodes {
...on Article {
...SearchArticle
}
}
}
}
` as const;

View File

@@ -0,0 +1,473 @@
:root {
--aside-width: 400px;
--cart-aside-summary-height-with-discount: 300px;
--cart-aside-summary-height: 250px;
--grid-item-width: 355px;
--header-height: 64px;
--color-dark: #000;
--color-light: #fff;
}
img {
border-radius: 4px;
}
/*
* --------------------------------------------------
* components/Aside
* --------------------------------------------------
*/
aside {
background: var(--color-light);
box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
height: 100vh;
max-width: var(--aside-width);
min-width: var(--aside-width);
position: fixed;
right: calc(-1 * var(--aside-width));
top: 0;
transition: transform 200ms ease-in-out;
}
aside header {
align-items: center;
border-bottom: 1px solid var(--color-dark);
display: flex;
height: var(--header-height);
justify-content: space-between;
padding: 0 20px;
}
aside header h3 {
margin: 0;
}
aside header .close {
font-weight: bold;
opacity: 0.8;
text-decoration: none;
transition: all 200ms;
width: 20px;
&:hover {
opacity: 1;
}
}
aside header h2 {
margin-bottom: 0.6rem;
margin-top: 0;
}
aside main {
margin: 1rem;
}
aside p {
margin: 0 0 0.25rem;
&:last-child {
margin: 0;
}
}
aside li {
margin-bottom: 0.125rem;
}
.overlay {
background: rgba(0, 0, 0, 0.2);
bottom: 0;
left: 0;
opacity: 0;
pointer-events: none;
position: fixed;
right: 0;
top: 0;
transition: opacity 400ms ease-in-out;
transition: opacity 400ms;
visibility: hidden;
z-index: 10;
}
.overlay .close-outside {
background: transparent;
border: none;
color: transparent;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: calc(100% - var(--aside-width));
}
.overlay .light {
background: rgba(255, 255, 255, 0.5);
}
.overlay .cancel {
cursor: default;
height: 100%;
position: absolute;
width: 100%;
}
.overlay {
&:target {
opacity: 1;
pointer-events: auto;
visibility: visible;
}
/* reveal aside */
&:target aside {
transform: translateX(calc(var(--aside-width) * -1));
}
}
/*
* --------------------------------------------------
* components/Header
* --------------------------------------------------
*/
.header {
align-items: center;
background: #fff;
display: flex;
height: var(--header-height);
padding: 0 1rem;
position: sticky;
top: 0;
z-index: 1;
}
.header-menu-mobile-toggle {
@media (min-width: 48em) {
display: none;
}
}
.header-menu-mobile {
display: flex;
flex-direction: column;
grid-gap: 1rem;
}
.header-menu-desktop {
display: none;
grid-gap: 1rem;
@media (min-width: 45em) {
display: flex;
grid-gap: 1rem;
margin-left: 3rem;
}
}
.header-menu-item {
cursor: pointer;
}
.header-ctas {
align-items: center;
display: flex;
grid-gap: 1rem;
margin-left: auto;
}
/*
* --------------------------------------------------
* components/Footer
* --------------------------------------------------
*/
.footer {
background: var(--color-dark);
margin-top: auto;
}
.footer-menu-missing {
display: inline-block;
margin: 1rem;
}
.footer-menu {
align-items: center;
display: flex;
grid-gap: 1rem;
padding: 1rem;
}
.footer-menu a {
color: var(--color-light);
}
/*
* --------------------------------------------------
* components/Cart
* --------------------------------------------------
*/
.cart-main {
height: 100%;
max-height: calc(100vh - var(--cart-aside-summary-height));
overflow-y: auto;
width: auto;
}
.cart-main.with-discount {
max-height: calc(100vh - var(--cart-aside-summary-height-with-discount));
}
.cart-line {
display: flex;
padding: 0.75rem 0;
}
.cart-line img {
height: 100%;
display: block;
margin-right: 0.75rem;
}
.cart-summary-page {
position: relative;
}
.cart-summary-aside {
background: white;
border-top: 1px solid var(--color-dark);
bottom: 0;
padding-top: 0.75rem;
position: absolute;
width: calc(var(--aside-width) - 40px);
}
.cart-line-quantiy {
display: flex;
}
.cart-discount {
align-items: center;
display: flex;
margin-top: 0.25rem;
}
.cart-subtotal {
align-items: center;
display: flex;
}
/*
* --------------------------------------------------
* components/Search
* --------------------------------------------------
*/
.predictive-search {
height: calc(100vh - var(--header-height) - 40px);
overflow-y: auto;
}
.predictive-search-form {
background: var(--color-light);
position: sticky;
top: 0;
}
.predictive-search-result {
margin-bottom: 2rem;
}
.predictive-search-result h5 {
text-transform: uppercase;
}
.predictive-search-result-item {
margin-bottom: 0.5rem;
}
.predictive-search-result-item a {
align-items: center;
display: flex;
}
.predictive-search-result-item a img {
margin-right: 0.75rem;
height: 100%;
}
.search-result {
margin-bottom: 1.5rem;
}
.search-results-item {
margin-bottom: 0.5rem;
}
/*
* --------------------------------------------------
* routes/__index
* --------------------------------------------------
*/
.featured-collection {
display: block;
margin-bottom: 2rem;
position: relative;
}
.featured-collection-image {
aspect-ratio: 1 / 1;
@media (min-width: 45em) {
aspect-ratio: 16 / 9;
}
}
.featured-collection img {
height: auto;
max-height: 100%;
object-fit: cover;
}
.recommended-products-grid {
display: grid;
grid-gap: 1.5rem;
grid-template-columns: repeat(2, 1fr);
@media (min-width: 45em) {
grid-template-columns: repeat(4, 1fr);
}
}
.recommended-product img {
height: auto;
}
/*
* --------------------------------------------------
* routes/collections._index.tsx
* --------------------------------------------------
*/
.collections-grid {
display: grid;
grid-gap: 1.5rem;
grid-template-columns: repeat(auto-fit, minmax(var(--grid-item-width), 1fr));
margin-bottom: 2rem;
}
.collection-item img {
height: auto;
}
/*
* --------------------------------------------------
* routes/collections.$handle.tsx
* --------------------------------------------------
*/
.collection-description {
margin-bottom: 1rem;
max-width: 95%;
@media (min-width: 45em) {
max-width: 600px;
}
}
.products-grid {
display: grid;
grid-gap: 1.5rem;
grid-template-columns: repeat(auto-fit, minmax(var(--grid-item-width), 1fr));
margin-bottom: 2rem;
}
.product-item img {
height: auto;
width: 100%;
}
/*
* --------------------------------------------------
* routes/products.$handle.tsx
* --------------------------------------------------
*/
.product {
display: grid;
@media (min-width: 45em) {
grid-template-columns: 1fr 1fr;
grid-gap: 4rem;
}
}
.product h1 {
margin-top: 0;
}
.product-images {
display: grid;
grid-gap: 1rem;
}
.product-image img {
height: auto;
width: 100%;
}
.product-main {
align-self: start;
position: sticky;
top: 6rem;
}
.product-price-on-sale {
display: flex;
grid-gap: 0.5rem;
}
.product-price-on-sale s {
opacity: 0.5;
}
.product-options-grid {
display: flex;
flex-wrap: wrap;
grid-gap: 0.75rem;
}
.product-options-item {
padding: 0.25rem 0.5rem;
}
/*
* --------------------------------------------------
* routes/blog._index.tsx
* --------------------------------------------------
*/
.blog-grid {
display: grid;
grid-gap: 1.5rem;
grid-template-columns: repeat(auto-fit, minmax(var(--grid-item-width), 1fr));
margin-bottom: 2rem;
}
.blog-article-image {
aspect-ratio: 3/2;
display: block;
}
.blog-article-image img {
height: 100%;
}
/*
* --------------------------------------------------
* routes/blog.$articlehandle.tsx
* --------------------------------------------------
*/
.article img {
height: auto;
width: 100%;
}
/*
* --------------------------------------------------
* routes/account
* --------------------------------------------------
*/
.account-profile-marketing {
display: flex;
align-items: center;
}
.account-logout {
display: inline-block;
}

Some files were not shown because too many files have changed in this diff Show More