-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
amannn
wants to merge
38
commits into
v4
Choose a base branch
from
feat/next-future
base: v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−57
Draft
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 f54b01d
upgrade example-app-router to latest next.js canary
amannn 550a734
dynamicIO, ppr, remove dynamicParams = false
amannn 096033a
read locale from `getLocale`, use hypothetical api to read params dee…
amannn e78099d
Lazy-init `now` when `useNow` or `format.relativeTime` is used in com…
amannn 7c528cf
Don't create default value for `now` when inheriting in `NextIntlClie…
amannn 246e828
update test
amannn 76adb07
fix test
amannn 99a3135
fix docs
amannn 7e11418
fix comment
amannn a892a44
fix test
amannn 6738b27
Merge branch 'feat/dio-now' into feat/next-future
amannn 36460f1
disable manifest for now
amannn 80b4aad
latest canary
amannn 2e83967
add suspense
amannn cf075fd
move suspense up a level
amannn 204b5df
feat!: Don't read a default for `locale` from `useParams.locale` on t…
amannn 4b678cd
adapt docs
amannn 17a9602
fix playground, minor docs fixes
amannn f9f15b9
Merge branch 'feat/dio-no-params' into feat/next-future
amannn 1e66d07
Lazy read `now` only when necessary in `createFormatter`
amannn 36230db
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn 79fea4f
Merge branch 'feat/dio-no-params' into feat/next-future
amannn b470184
bump size
amannn 3e9a7c7
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn ea3d97d
Merge branch 'feat/dio-no-params' into feat/next-future
amannn 6063dd2
fix race condition for linting example-app-router-playground
amannn 0de0e48
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn fe9ede2
Merge branch 'feat/dio-no-params' into feat/next-future
amannn 846fae8
fix syntax error
amannn 2e9d353
Merge branch 'feat/dio-now' into feat/dio-no-params
amannn 9ccc4a0
Merge branch 'feat/dio-no-params' into feat/next-future
amannn b483092
remove global now
amannn 0eac577
Merge remote-tracking branch 'origin/v4' into feat/next-future
amannn 0172f35
revert docs changes
amannn eaf67fa
Merge remote-tracking branch 'origin/v4' into feat/next-future
amannn 7e09d85
small improvement
amannn 353fa17
use case for overriding locale [skip ci]
amannn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
examples/example-app-router/src/app/[locale]/pathnames/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function rootParams(): Promise<{ | ||
locale?: string; | ||
}> { | ||
// Outside of `[locale]` | ||
// return Promise.resolve({ | ||
// locale: undefined | ||
// }); | ||
|
||
// In `[locale]` | ||
return Promise.resolve({ | ||
locale: 'en' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Revert |
||
messages | ||
}; | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.