bump next-intl to RSC support

This commit is contained in:
Sol Irvine
2023-11-13 14:30:39 +09:00
parent ecf1205825
commit 7fa6ffbe2a
23 changed files with 102 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getPage, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import AboutNaraiDetail from './about-narai-detail';
@@ -19,6 +20,10 @@ export const metadata = {
};
export default async function Page({ params }: { params: { locale?: SupportedLocale } }) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import SagyobarDetail from './sagyobar-detail';
@@ -19,6 +20,10 @@ export const metadata = {
};
export default async function Page({ params }: { params: { locale?: SupportedLocale } }) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import CompanyDetail from './company-detail';
@@ -19,6 +20,10 @@ export const metadata = {
};
export default async function Page({ params }: { params: { locale?: SupportedLocale } }) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import ConceptDetail from './concept-detail';
@@ -19,6 +20,10 @@ export const metadata = {
};
export default async function Page({ params }: { params: { locale?: SupportedLocale } }) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import Disclosures from './disclosures';
@@ -23,6 +24,10 @@ export default async function DisclosuresPage({
}: {
params: { locale?: SupportedLocale };
}) {
if (!!locale) {
unstable_setRequestLocale(locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,8 @@ import { ReactNode, Suspense } from 'react';
import { SupportedLocale } from 'components/layout/navbar/language-control';
import { NextIntlClientProvider } from 'next-intl';
import { unstable_setRequestLocale } from 'next-intl/server';
import { notFound } from 'next/navigation';
import Analytics from './analytics';
import './globals.css';
@@ -69,8 +71,10 @@ const noto = Noto_Serif_JP({
variable: '--font-noto'
});
export const SupportedLocales: SupportedLocale[] = ['ja', 'en'];
export function generateStaticParams() {
return [{ locale: 'ja' }, { locale: 'en' }];
return SupportedLocales.map((locale) => ({ locale }));
}
export default async function RootLayout({
@@ -80,6 +84,14 @@ export default async function RootLayout({
children: ReactNode;
params: { locale?: SupportedLocale };
}) {
// Validate that the incoming `locale` parameter is valid
const isValidLocale = SupportedLocales.some((cur: string) => cur === params?.locale);
if (!isValidLocale) notFound();
if (params?.locale) {
unstable_setRequestLocale(params.locale);
}
const messages = (await import(`../../messages/${params?.locale}.json`)).default;
return (

View File

@@ -22,6 +22,7 @@ import StoriesPreview from 'components/layout/stories-preview';
import { BLOG_HANDLE } from 'lib/constants';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import Image from 'next/image';
import { Suspense } from 'react';
@@ -41,6 +42,10 @@ export default async function HomePage({
}: {
params: { locale?: SupportedLocale };
}) {
if (!!locale) {
unstable_setRequestLocale(locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import PrivacyPolicy from './privacy-policy';
@@ -23,6 +24,10 @@ export default async function PrivacyPage({
}: {
params: { locale?: SupportedLocale };
}) {
if (!!locale) {
unstable_setRequestLocale(locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -1,5 +1,4 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { ChevronDoubleRightIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
@@ -14,6 +13,7 @@ import { VariantSelector } from 'components/product/variant-selector';
import { HIDDEN_PRODUCT_TAG } from 'lib/constants';
import { getProduct, getProductRecommendations } from 'lib/shopify';
import { Image as MediaImage, Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import Image from 'next/image';
import Link from 'next/link';
import { Suspense } from 'react';
@@ -28,7 +28,7 @@ export async function generateMetadata({
language: params?.locale?.toUpperCase()
});
if (!product) return notFound();
if (!product) return {};
const { url, width, height, altText: alt } = product.featuredImage || {};
const indexable = !product.tags.includes(HIDDEN_PRODUCT_TAG);
@@ -64,6 +64,10 @@ export default async function ProductPage({
}: {
params: { handle: string; locale?: SupportedLocale };
}) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const numberOfOtherImages = 3;
const product = await getProduct({
handle: params.handle,
@@ -77,7 +81,7 @@ export default async function ProductPage({
.filter((image) => image?.url !== product.featuredImage?.url);
}
if (!product) return notFound();
if (!product) return {};
const productJsonLd = {
'@context': 'https://schema.org',

View File

@@ -5,6 +5,7 @@ import { ProductGrid } from 'components/grid/product-grid';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
@@ -23,6 +24,10 @@ export default async function ProductPage({
}: {
params: { locale?: SupportedLocale };
}) {
if (!!locale) {
unstable_setRequestLocale(locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -5,9 +5,9 @@ import Navbar from 'components/layout/navbar';
import { SupportedLocale } from 'components/layout/navbar/language-control';
import { getCart, getPage, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { unstable_noStore } from 'next/cache';
import { cookies } from 'next/headers';
import { notFound } from 'next/navigation';
import { Suspense } from 'react';
import ShopListDetail from './shop-list-detail';
import ShopsNav from './shops-nav';
@@ -23,7 +23,7 @@ export async function generateMetadata({
language: params?.locale?.toUpperCase() || 'JA'
});
if (!page) return notFound();
if (!page) return {};
return {
title: page.seo?.title || page.title,
@@ -37,6 +37,10 @@ export async function generateMetadata({
}
export default async function Page({ params }: { params: { locale?: SupportedLocale } }) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;

View File

@@ -7,7 +7,7 @@ import { notFound } from 'next/navigation';
export default async function ShopListDetail({ language }: { language?: string }) {
const page = await getPage({ handle: 'shop-list', language });
if (!page) return notFound();
if (!page) notFound();
return <Prose html={page.body as string} />;
}

View File

@@ -6,6 +6,7 @@ import Prose from 'components/prose';
import { BLOG_HANDLE, HIDDEN_ARTICLE_TAG } from 'lib/constants';
import { getBlogArticle } from 'lib/shopify';
import { BlogArticle } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import Image from 'next/image';
export async function generateMetadata({
@@ -19,7 +20,7 @@ export async function generateMetadata({
language: params?.locale?.toUpperCase()
});
if (!article) return notFound();
if (!article) return {};
const { url, width, height, altText: alt } = article.image || {};
const indexable = !article?.tags?.includes(HIDDEN_ARTICLE_TAG);
@@ -55,13 +56,17 @@ export default async function BlogArticlePage({
}: {
params: { handle: string; locale?: SupportedLocale };
}) {
if (!!params?.locale) {
unstable_setRequestLocale(params.locale);
}
const article: BlogArticle | undefined = await getBlogArticle({
handle: BLOG_HANDLE,
articleHandle: params.handle,
language: params?.locale?.toUpperCase()
});
if (!article) return notFound();
if (!article) notFound();
return (
<>

View File

@@ -4,6 +4,7 @@ import { SupportedLocale } from 'components/layout/navbar/language-control';
import Navbar from 'components/layout/navbar';
import { getCart, getProduct } from 'lib/shopify';
import { Product } from 'lib/shopify/types';
import { unstable_setRequestLocale } from 'next-intl/server';
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import TermsOfUse from './terms-of-use';
@@ -23,6 +24,10 @@ export default async function TermsPage({
}: {
params: { locale?: SupportedLocale };
}) {
if (!!locale) {
unstable_setRequestLocale(locale);
}
const cartId = cookies().get('cartId')?.value;
let cart;