Skip to content

Commit

Permalink
Update to 15 RC 2
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob committed Oct 16, 2024
1 parent 694c5c1 commit 64ca2ac
Show file tree
Hide file tree
Showing 18 changed files with 1,170 additions and 592 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Vercel is happy to partner and work with any commerce provider to help them get
Integrations enable upgraded or additional functionality for Next.js Commerce

- [Orama](https://github.com/oramasearch/nextjs-commerce) ([Demo](https://vercel-commerce.oramasearch.com/))

- Upgrades search to include typeahead with dynamic re-rendering, vector-based similarity search, and JS-based configuration.
- Search runs entirely in the browser for smaller catalogs or on a CDN for larger.

Expand Down
10 changes: 5 additions & 5 deletions app/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import Prose from 'components/prose';
import { getPage } from 'lib/shopify';
import { notFound } from 'next/navigation';

export async function generateMetadata({
params
}: {
params: { page: string };
export async function generateMetadata(props: {
params: Promise<{ page: string }>;
}): Promise<Metadata> {
const params = await props.params;
const page = await getPage(params.page);

if (!page) return notFound();
Expand All @@ -24,7 +23,8 @@ export async function generateMetadata({
};
}

export default async function Page({ params }: { params: { page: string } }) {
export default async function Page(props: { params: Promise<{ page: string }> }) {
const params = await props.params;
const page = await getPage(params.page);

if (!page) return notFound();
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const metadata = {
};

export default async function RootLayout({ children }: { children: ReactNode }) {
const cartId = cookies().get('cartId')?.value;
const cartId = (await cookies()).get('cartId')?.value;
// Don't await the fetch, pass the Promise to the context provider
const cart = getCart(cartId);

Expand Down
10 changes: 5 additions & 5 deletions app/product/[handle]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import { Image } from 'lib/shopify/types';
import Link from 'next/link';
import { Suspense } from 'react';

export async function generateMetadata({
params
}: {
params: { handle: string };
export async function generateMetadata(props: {
params: Promise<{ handle: string }>;
}): Promise<Metadata> {
const params = await props.params;
const product = await getProduct(params.handle);

if (!product) return notFound();
Expand Down Expand Up @@ -50,7 +49,8 @@ export async function generateMetadata({
};
}

export default async function ProductPage({ params }: { params: { handle: string } }) {
export default async function ProductPage(props: { params: Promise<{ handle: string }> }) {
const params = await props.params;
const product = await getProduct(params.handle);

if (!product) return notFound();
Expand Down
18 changes: 8 additions & 10 deletions app/search/[collection]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import Grid from 'components/grid';
import ProductGridItems from 'components/layout/product-grid-items';
import { defaultSort, sorting } from 'lib/constants';

export async function generateMetadata({
params
}: {
params: { collection: string };
export async function generateMetadata(props: {
params: Promise<{ collection: string }>;
}): Promise<Metadata> {
const params = await props.params;
const collection = await getCollection(params.collection);

if (!collection) return notFound();
Expand All @@ -22,13 +21,12 @@ export async function generateMetadata({
};
}

export default async function CategoryPage({
params,
searchParams
}: {
params: { collection: string };
searchParams?: { [key: string]: string | string[] | undefined };
export default async function CategoryPage(props: {
params: Promise<{ collection: string }>;
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const searchParams = await props.searchParams;
const params = await props.params;
const { sort } = searchParams as { [key: string]: string };
const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
const products = await getCollectionProducts({ collection: params.collection, sortKey, reverse });
Expand Down
7 changes: 3 additions & 4 deletions app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ export const metadata = {
description: 'Search for products in the store.'
};

export default async function SearchPage({
searchParams
}: {
searchParams?: { [key: string]: string | string[] | undefined };
export default async function SearchPage(props: {
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const searchParams = await props.searchParams;
const { sort, q: searchValue } = searchParams as { [key: string]: string };
const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;

Expand Down
10 changes: 5 additions & 5 deletions components/cart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';

export async function addItem(prevState: any, selectedVariantId: string | undefined) {
let cartId = cookies().get('cartId')?.value;
let cartId = (await cookies()).get('cartId')?.value;

if (!cartId || !selectedVariantId) {
return 'Error adding item to cart';
Expand All @@ -22,7 +22,7 @@ export async function addItem(prevState: any, selectedVariantId: string | undefi
}

export async function removeItem(prevState: any, merchandiseId: string) {
let cartId = cookies().get('cartId')?.value;
let cartId = (await cookies()).get('cartId')?.value;

if (!cartId) {
return 'Missing cart ID';
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function updateItemQuantity(
quantity: number;
}
) {
let cartId = cookies().get('cartId')?.value;
let cartId = (await cookies()).get('cartId')?.value;

if (!cartId) {
return 'Missing cart ID';
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function updateItemQuantity(
}

export async function redirectToCheckout() {
let cartId = cookies().get('cartId')?.value;
let cartId = (await cookies()).get('cartId')?.value;

if (!cartId) {
return 'Missing cart ID';
Expand All @@ -114,5 +114,5 @@ export async function redirectToCheckout() {

export async function createCartAndSetCookie() {
let cart = await createCart();
cookies().set('cartId', cart.id!);
(await cookies()).set('cartId', cart.id!);
}
4 changes: 2 additions & 2 deletions components/cart/add-to-cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import clsx from 'clsx';
import { addItem } from 'components/cart/actions';
import { useProduct } from 'components/product/product-context';
import { Product, ProductVariant } from 'lib/shopify/types';
import { useFormState } from 'react-dom';
import { useActionState } from 'react';
import { useCart } from './cart-context';

function SubmitButton({
Expand Down Expand Up @@ -62,7 +62,7 @@ export function AddToCart({ product }: { product: Product }) {
const { variants, availableForSale } = product;
const { addCartItem } = useCart();
const { state } = useProduct();
const [message, formAction] = useFormState(addItem, null);
const [message, formAction] = useActionState(addItem, null);

const variant = variants.find((variant: ProductVariant) =>
variant.selectedOptions.every((option) => option.value === state[option.name.toLowerCase()])
Expand Down
4 changes: 2 additions & 2 deletions components/cart/delete-item-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { XMarkIcon } from '@heroicons/react/24/outline';
import { removeItem } from 'components/cart/actions';
import type { CartItem } from 'lib/shopify/types';
import { useFormState } from 'react-dom';
import { useActionState } from 'react';

export function DeleteItemButton({
item,
Expand All @@ -12,7 +12,7 @@ export function DeleteItemButton({
item: CartItem;
optimisticUpdate: any;
}) {
const [message, formAction] = useFormState(removeItem, null);
const [message, formAction] = useActionState(removeItem, null);
const merchandiseId = item.merchandise.id;
const actionWithVariant = formAction.bind(null, merchandiseId);

Expand Down
4 changes: 2 additions & 2 deletions components/cart/edit-item-quantity-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MinusIcon, PlusIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
import { updateItemQuantity } from 'components/cart/actions';
import type { CartItem } from 'lib/shopify/types';
import { useFormState } from 'react-dom';
import { useActionState } from 'react';

function SubmitButton({ type }: { type: 'plus' | 'minus' }) {
return (
Expand Down Expand Up @@ -36,7 +36,7 @@ export function EditItemQuantityButton({
type: 'plus' | 'minus';
optimisticUpdate: any;
}) {
const [message, formAction] = useFormState(updateItemQuantity, null);
const [message, formAction] = useActionState(updateItemQuantity, null);
const payload = {
merchandiseId: item.merchandise.id,
quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export async function revalidate(req: NextRequest): Promise<NextResponse> {
// otherwise it will continue to retry the request.
const collectionWebhooks = ['collections/create', 'collections/delete', 'collections/update'];
const productWebhooks = ['products/create', 'products/delete', 'products/update'];
const topic = headers().get('x-shopify-topic') || 'unknown';
const topic = (await headers()).get('x-shopify-topic') || 'unknown';
const secret = req.nextUrl.searchParams.get('secret');
const isCollectionUpdate = collectionWebhooks.includes(topic);
const isProductUpdate = productWebhooks.includes(topic);
Expand Down
2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Vercel, Inc.
Copyright (c) 2024 Vercel, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions next.config.js → next.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @type {import('next').NextConfig} */
module.exports = {
export default {
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@
"@heroicons/react": "^2.1.5",
"clsx": "^2.1.1",
"geist": "^1.3.1",
"next": "15.0.0-canary.113",
"react": "19.0.0-rc-3208e73e-20240730",
"react-dom": "19.0.0-rc-3208e73e-20240730",
"next": "15.0.0-rc.1",
"react": "19.0.0-rc-cd22717c-20241013",
"react-dom": "19.0.0-rc-cd22717c-20241013",
"sonner": "^1.5.0"
},
"devDependencies": {
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.13",
"@types/node": "20.14.12",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.39",
"prettier": "3.3.3",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.6",
"typescript": "5.5.4"
},
"pnpm": {
"overrides": {
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
}
}
}
Loading

0 comments on commit 64ca2ac

Please sign in to comment.