Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Exploration of ppr, dynamicIO and rootParams #1531

Draft
wants to merge 38 commits into
base: v4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d1a0308
Use `dynamicParams = false` instead of manually calling `notFound()`
amannn Nov 11, 2024
f54b01d
upgrade example-app-router to latest next.js canary
amannn Nov 11, 2024
550a734
dynamicIO, ppr, remove dynamicParams = false
amannn Nov 11, 2024
096033a
read locale from `getLocale`, use hypothetical api to read params dee…
amannn Nov 12, 2024
e78099d
Lazy-init `now` when `useNow` or `format.relativeTime` is used in com…
amannn Nov 12, 2024
7c528cf
Don't create default value for `now` when inheriting in `NextIntlClie…
amannn Nov 12, 2024
246e828
update test
amannn Nov 13, 2024
76adb07
fix test
amannn Nov 13, 2024
99a3135
fix docs
amannn Nov 13, 2024
7e11418
fix comment
amannn Nov 13, 2024
a892a44
fix test
amannn Nov 13, 2024
6738b27
Merge branch 'feat/dio-now' into feat/next-future
amannn Nov 13, 2024
36460f1
disable manifest for now
amannn Nov 13, 2024
80b4aad
latest canary
amannn Nov 13, 2024
2e83967
add suspense
amannn Nov 13, 2024
cf075fd
move suspense up a level
amannn Nov 13, 2024
204b5df
feat!: Don't read a default for `locale` from `useParams.locale` on t…
amannn Nov 13, 2024
4b678cd
adapt docs
amannn Nov 13, 2024
17a9602
fix playground, minor docs fixes
amannn Nov 13, 2024
f9f15b9
Merge branch 'feat/dio-no-params' into feat/next-future
amannn Nov 13, 2024
1e66d07
Lazy read `now` only when necessary in `createFormatter`
amannn Nov 14, 2024
36230db
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn Nov 14, 2024
79fea4f
Merge branch 'feat/dio-no-params' into feat/next-future
amannn Nov 14, 2024
b470184
bump size
amannn Nov 14, 2024
3e9a7c7
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn Nov 14, 2024
ea3d97d
Merge branch 'feat/dio-no-params' into feat/next-future
amannn Nov 14, 2024
6063dd2
fix race condition for linting example-app-router-playground
amannn Nov 14, 2024
0de0e48
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn Nov 14, 2024
fe9ede2
Merge branch 'feat/dio-no-params' into feat/next-future
amannn Nov 14, 2024
846fae8
fix syntax error
amannn Nov 14, 2024
2e9d353
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn Nov 14, 2024
9ccc4a0
Merge branch 'feat/dio-no-params' into feat/next-future
amannn Nov 14, 2024
b483092
remove global now
amannn Nov 14, 2024
0eac577
Merge remote-tracking branch 'origin/v4' into feat/next-future
amannn Nov 14, 2024
0172f35
revert docs changes
amannn Nov 14, 2024
eaf67fa
Merge remote-tracking branch 'origin/v4' into feat/next-future
amannn Nov 19, 2024
7e09d85
small improvement
amannn Nov 19, 2024
353fa17
use case for overriding locale [skip ci]
amannn Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example-app-router/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
7 changes: 6 additions & 1 deletion examples/example-app-router/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const withNextIntl = createNextIntlPlugin({
});

/** @type {import('next').NextConfig} */
const config = {};
const config = {
experimental: {
dynamicIO: true,
ppr: true
}
};

export default withNextIntl(config);
2 changes: 1 addition & 1 deletion examples/example-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"clsx": "^2.1.1",
"next": "^14.2.4",
"next": "15.0.4-canary.8",
"next-intl": "^3.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
24 changes: 10 additions & 14 deletions examples/example-app-router/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import {notFound} from 'next/navigation';
import {Locale, hasLocale} from 'next-intl';
import {getTranslations, setRequestLocale} from 'next-intl/server';
import {hasLocale} from 'next-intl';
import {getTranslations} from 'next-intl/server';
import {ReactNode} from 'react';
import BaseLayout from '@/components/BaseLayout';
import {routing} from '@/i18n/routing';

type Props = {
children: ReactNode;
params: {locale: Locale};
params: Promise<{
locale: string;
}>;
};

export function generateStaticParams() {
return routing.locales.map((locale) => ({locale}));
}

export async function generateMetadata({
params: {locale}
}: Omit<Props, 'children'>) {
const t = await getTranslations({locale, namespace: 'LocaleLayout'});
export async function generateMetadata() {
const t = await getTranslations('LocaleLayout');

return {
title: t('title')
};
}

export default async function LocaleLayout({
children,
params: {locale}
}: Props) {
export default async function LocaleLayout({children, params}: Props) {
// This is only necessary as long as there's no `dynamicParams = false`
const {locale} = await params;
if (!hasLocale(routing.locales, locale)) {
notFound();
}

// Enable static rendering
setRequestLocale(locale);

return <BaseLayout locale={locale}>{children}</BaseLayout>;
}
12 changes: 2 additions & 10 deletions examples/example-app-router/src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {Locale, useTranslations} from 'next-intl';
import {setRequestLocale} from 'next-intl/server';
import {useTranslations} from 'next-intl';
import PageLayout from '@/components/PageLayout';

type Props = {
params: {locale: Locale};
};

export default function IndexPage({params: {locale}}: Props) {
// Enable static rendering
setRequestLocale(locale);

export default function IndexPage() {
const t = useTranslations('IndexPage');

return (
Expand Down
12 changes: 2 additions & 10 deletions examples/example-app-router/src/app/[locale]/pathnames/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {Locale, useTranslations} from 'next-intl';
import {setRequestLocale} from 'next-intl/server';
import {useTranslations} from 'next-intl';
import PageLayout from '@/components/PageLayout';

type Props = {
params: {locale: Locale};
};

export default function PathnamesPage({params: {locale}}: Props) {
// Enable static rendering
setRequestLocale(locale);

export default function PathnamesPage() {
const t = useTranslations('PathnamesPage');

return (
Expand Down
1 change: 1 addition & 0 deletions examples/example-app-router/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ type Props = {
// Since we have a `not-found.tsx` page on the root, a layout file
// is required, even if it's just passing children through.
export default function RootLayout({children}: Props) {
// TODO: Can we get rid of this?
return children;
}
7 changes: 3 additions & 4 deletions examples/example-app-router/src/app/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {MetadataRoute} from 'next';
import {getTranslations} from 'next-intl/server';

export default async function manifest(): Promise<MetadataRoute.Manifest> {
const locale = 'en';
const t = await getTranslations({locale, namespace: 'Manifest'});
// const t = await getTranslations('Manifest');

return {
name: t('name'),
// InvariantError: Invariant: Missing Client Reference Manifest for /manifest.webmanifest. This is a bug in Next.js.
// name: t('name'),
start_url: '/',
theme_color: '#101E33'
};
Expand Down
12 changes: 7 additions & 5 deletions examples/example-app-router/src/components/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {clsx} from 'clsx';
import {Inter} from 'next/font/google';
import {NextIntlClientProvider} from 'next-intl';
import {getMessages} from 'next-intl/server';
import {ReactNode} from 'react';
import {ReactNode, Suspense} from 'react';
import Navigation from '@/components/Navigation';

const inter = Inter({subsets: ['latin']});
Expand All @@ -20,10 +20,12 @@ export default async function BaseLayout({children, locale}: Props) {
return (
<html className="h-full" lang={locale}>
<body className={clsx(inter.className, 'flex h-full flex-col')}>
<NextIntlClientProvider messages={messages}>
<Navigation />
{children}
</NextIntlClientProvider>
<Suspense>
Copy link
Owner Author

@amannn amannn Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ideally work without this (probably requires an equivalent of dynamicParams = false.

<NextIntlClientProvider messages={messages}>
<Navigation />
{children}
</NextIntlClientProvider>
</Suspense>
</body>
</html>
);
Expand Down
13 changes: 13 additions & 0 deletions examples/example-app-router/src/i18n/future.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export async function rootParams(): Promise<{
locale?: string;
}> {
// Outside of `[locale]`
// return Promise.resolve({
// locale: undefined
// });

// In `[locale]`
return Promise.resolve({
locale: 'en'
});
}
13 changes: 7 additions & 6 deletions examples/example-app-router/src/i18n/request.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {hasLocale} from 'next-intl';
import {getRequestConfig} from 'next-intl/server';
import messages from '../../messages/en.json';
import {rootParams} from './future';
import {routing} from './routing';

export default getRequestConfig(async ({requestLocale}) => {
// Typically corresponds to the `[locale]` segment
const requested = await requestLocale;
const locale = hasLocale(routing.locales, requested)
? requested
export default getRequestConfig(async () => {
const params = await rootParams();
const locale = hasLocale(routing.locales, params.locale)
? params.locale
: routing.defaultLocale;

return {
locale,
messages: (await import(`../../messages/${locale}.json`)).default
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Revert

messages
};
});
Loading
Loading