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(RSC): Remove deprecations and RSC-first docs #522

Merged
merged 29 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a50d4dd
Add blog post for RC
amannn Sep 22, 2023
ae9b582
Remove deprecations
amannn Sep 22, 2023
8b85ffb
More cleanup
amannn Sep 22, 2023
4174ee4
Upgrade app
amannn Sep 22, 2023
854bbcc
Revert docs changes, remove createIntl call site
amannn Sep 22, 2023
fcb7065
Change `localePrefix` default to `always`
amannn Sep 26, 2023
9d39844
Wording [skip ci]
amannn Sep 26, 2023
f6e867b
Fix tests by setting `localePrefix` explicitly
amannn Sep 26, 2023
20351f6
Easier matcher based on new default
amannn Sep 26, 2023
76700d2
Remove `next-intl/link` and `redirect` from `next-intl/server`, and e…
amannn Sep 26, 2023
6453d51
Rename link and redirect for clarity
amannn Sep 26, 2023
5ed88cc
Update examples
amannn Sep 26, 2023
187ee4f
Remove `next-intl/client`, move and rename APIs
amannn Sep 26, 2023
00e4e02
More cleanup
amannn Sep 26, 2023
9aa94d0
More cleanup
amannn Sep 26, 2023
200e986
Fix build
amannn Sep 26, 2023
63dcb08
Fix build
amannn Sep 26, 2023
4ee78bf
Pass default `timeZone` from RSC to client and add warning for missin…
amannn Sep 26, 2023
b6d2536
Bump sizes
amannn Sep 26, 2023
683bafb
Add banner, improve matcher docs
amannn Sep 27, 2023
3f4869f
Update slug for blog post
amannn Sep 27, 2023
39e56ef
Remove production checklist and move runtime requirements
amannn Sep 27, 2023
01bb859
RSC-first docs
amannn Sep 27, 2023
0e54b4c
Move configration page to usage
amannn Sep 27, 2023
5c58fbb
Update issue template [skip ci]
amannn Sep 27, 2023
37c2cb2
Wording
amannn Sep 28, 2023
0c62f86
Add note about RSC usage
amannn Sep 28, 2023
db0acb4
Wording
amannn Sep 28, 2023
ed09c78
Merge branch 'feat/next-13-rsc' into feat/next-13-rsc-rc
amannn Sep 28, 2023
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
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ body:
label: Mandatory reproduction URL (CodeSandbox or GitHub repository)
description: |
**Templates:**
- [CodeSandbox (`app` directory)](https://codesandbox.io/p/sandbox/next-intl-bug-template-forked-yow8ep)
- [CodeSandbox (`app` directory, RSC beta)](https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-zcymvq)
- [CodeSandbox (`pages` directory)](https://codesandbox.io/p/sandbox/next-intl-bug-template-pages-krm37f)
- [CodeSandbox (App Router)](https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-zcymvq)
- [CodeSandbox (Pages Router)](https://codesandbox.io/p/sandbox/next-intl-bug-template-pages-krm37f)
validations:
required: true
- type: textarea
Expand Down
6 changes: 3 additions & 3 deletions docs/components/CodeSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ function buildOutput() {
<span style={{color: 'var(--shiki-color-text)'}}> kB</span>
<span style={{color: 'var(--shiki-color-text)'}}>{' '}</span>
<span style={{color: 'var(--shiki-token-string-expression)'}}>
104 kB
87.6 kB
</span>
</span>
<span className="line">
Expand All @@ -358,7 +358,7 @@ function buildOutput() {
<span style={{color: 'var(--shiki-color-text)'}}> B</span>
<span style={{color: 'var(--shiki-color-text)'}}>{' '}</span>
<span style={{color: 'var(--shiki-token-string-expression)'}}>
97.5 kB
80.2 kB
</span>
</span>
<span className="line">
Expand All @@ -368,7 +368,7 @@ function buildOutput() {
<span style={{color: 'var(--shiki-color-text)'}}> kB</span>
<span style={{color: 'var(--shiki-color-text)'}}>{' '}</span>
<span style={{color: 'var(--shiki-token-string-expression)'}}>
106 kB
89.3 kB
</span>
</span>
<span className="line"> </span>
Expand Down
31 changes: 0 additions & 31 deletions docs/components/VersionTabs.tsx

This file was deleted.

34 changes: 22 additions & 12 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ module.exports = withNextra({
},
{
source: '/docs/getting-started/production-checklist',
destination: '/docs/production-checklist',
destination: '/docs/environments/runtime-requirements',
permanent: true
},
{
source: '/docs/usage/production-checklist',
destination: '/docs/production-checklist',
destination: '/docs/environments/runtime-requirements',
permanent: true
},
{
source: '/docs/production-checklist',
destination: '/docs/environments/runtime-requirements',
permanent: true
},
{
Expand All @@ -45,12 +50,22 @@ module.exports = withNextra({
},
{
source: '/docs/next-13/client-components',
destination: '/docs/getting-started/app-router-client-components',
destination: '/docs/getting-started/app-router',
permanent: true
},
{
source: '/docs/next-13/server-components',
destination: '/docs/getting-started/app-router-server-components',
destination: '/docs/getting-started/app-router',
permanent: true
},
{
source: '/docs/getting-started/app-router-server-components',
destination: '/docs/getting-started/app-router',
permanent: true
},
{
source: '/docs/getting-started/app-router-client-components',
destination: '/docs/getting-started/app-router',
permanent: true
},
{
Expand All @@ -75,22 +90,17 @@ module.exports = withNextra({
},
{
source: '/docs/usage/production-checklist',
destination: '/docs/production-checklist',
destination: '/docs/environments/runtime-requirements',
permanent: true
},
{
source: '/docs/usage/runtime-requirements-polyfills',
destination: '/docs/production-checklist#runtime-requirements',
permanent: true
},
{
source: '/docs/usage/configuration',
destination: '/docs/configuration',
destination: '/docs/environments/runtime-requirements',
permanent: true
},
{
source: '/docs/usage/error-handling',
destination: '/docs/configuration#error-handling',
destination: '/docs/usage/configuration#error-handling',
permanent: true
},
{
Expand Down
2 changes: 0 additions & 2 deletions docs/pages/blog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import CommunityLink from 'components/CommunityLink';

# next-intl blog

Failed attempts at writing docs that somehow turned into blog posts.

<div className="flex flex-col gap-4 py-8">
<CommunityLink
href="/blog/translations-outside-of-react-components"
Expand Down
15 changes: 5 additions & 10 deletions docs/pages/blog/translations-outside-of-react-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,21 @@ Additionally, this approach is more robust to possibly unexpected states, like t

If you’re working with Next.js, you might want to translate i18n messages in [API routes](https://nextjs.org/docs/pages/building-your-application/routing/api-routes), [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) or the [Metadata API](https://nextjs.org/docs/app/api-reference/file-conventions/metadata).

`next-intl` provides a [core library](/docs/environments/core-library) that is agnostic from React and can be used for these cases.
`next-intl/server` provides a set of awaitable versions of the functions that you usually call as hooks from within components. These are agnostic from React and can be used for these cases.

```tsx
import {createTranslator} from 'next-intl';
import {getTranslator} from 'next-intl/server';

const messages = {
hello: 'Hello {name}!'
};
// The `locale` is received from Next.js via `params`
const locale = params.locale;

// This creates the same function that is returned by `useTranslations`.
// Since there's no provider, you can pass all the properties you'd
// usually pass to the provider directly here.
const t = createTranslator({locale: 'en', messages});
const t = await getTranslator(locale);

// Result: "Hello world!"
t('hello', {name: 'world'});
```

There's currently a proposal to further simplify this use case, by offering a set of [new APIs that integrate with Server Components](/docs/environments/metadata-route-handlers) (currently in beta).

## This seems familiar

If you’ve been working with React for a longer time, you might have experienced the change [from `component{DidMount,DidUpdate,WillUnmount}` to `useEffect`](https://legacy.reactjs.org/docs/hooks-effect.html#explanation-why-effects-run-on-each-update). The reason why `useEffect` is superior is because it nudges the developer into a direction where the app is always in sync and by doing this, a whole array of potential issues just magically disappear.
Expand Down
2 changes: 0 additions & 2 deletions docs/pages/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"getting-started": "Getting started",
"usage": "Usage guide",
"environments": "Environments",
"configuration": "Global configuration",
"routing": "Routing",
"workflows": "Workflows & integrations",
"production-checklist": "Production checklist",
"faq": "FAQ"
}
3 changes: 2 additions & 1 deletion docs/pages/docs/environments/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"server-client-components": "Server & Client Components",
"metadata-route-handlers": "Metadata & Route Handlers",
"error-files": "Error files (e.g. not-found)",
"core-library": "Core library"
"core-library": "Core library",
"runtime-requirements": "Runtime requirements"
}
26 changes: 6 additions & 20 deletions docs/pages/docs/environments/error-files.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import VersionTabs from 'components/VersionTabs';
import Callout from 'components/Callout';

# Internationalization in Next.js error files
Expand Down Expand Up @@ -70,7 +69,7 @@ export default function NotFound() {
}
```

Note that the presence of `app/not-found.tsx` requires that a root layout is available as well, even if it's just passing `children` through.
Note that the presence of `app/not-found.tsx` requires that a root layout is available, even if it's just passing `children` through.

```tsx filename="app/layout.tsx"
// Since we have a root `not-found.tsx` page, a layout file
Expand All @@ -89,12 +88,8 @@ import {notFound} from 'next/navigation';
const locales = ['en', 'de'];

export default function LocaleLayout({children, params}) {
const locale = useLocale();

// Validate that the incoming `locale` parameter is a valid locale
if (params.locale !== locale) {
notFound();
}
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) notFound();

return (
<html lang={locale}>
Expand Down Expand Up @@ -125,11 +120,7 @@ When an `error` file is defined, Next.js creates [an error boundary within your

</figure>

Since the `error` file must be defined as a Client Component, you have to use [`NextIntlClientProvider`](/docs/configuration#client-server-components) to provide messages in case the `error` file renders.

If you've [set up `next-intl` to be used in Client Components](/docs/getting-started/app-router-client-components), this is already the case and there's no additional setup needed. If you're using [the Server Components beta](/docs/getting-started/app-router-server-components) though, you have to provide the relevant messages in the wrapping layout.

<figure>
Since the `error` file must be defined as a Client Component, you have to use [`NextIntlClientProvider`](/docs/usage/configuration#nextintlclientprovider) to provide messages in case the `error` file renders.

```tsx filename="app/[locale]/layout.tsx"
import pick from 'lodash/pick';
Expand All @@ -153,13 +144,6 @@ export default async function LocaleLayout({children}) {
}
```

<figcaption>
Providing messages for the `error` file is only necessary when using [the
Server Components beta](/docs/getting-started/app-router-server-components).
</figcaption>

</figure>

Once `NextIntlClientProvider` is in place, you can use functionality from `next-intl` in the `error` file:

```tsx filename="app/[locale]/error.tsx"
Expand All @@ -178,3 +162,5 @@ export default function Error({error, reset}) {
);
}
```

Note that `NextIntlClientProvider` only provides the messages to your error page, but doesn't load any runtime code for processing translations on the client side. Only the error page will include this code, so the performance of other pages isn't affected.
2 changes: 2 additions & 0 deletions docs/pages/docs/environments/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ The `next-intl` APIs are available in the following environments:
href="/docs/environments/core-library"
/>
</div>

While modern browsers and server runtimes typically support all necessary JavaScript APIs that are required for `next-intl`, you can double check [the runtime requirements](/docs/environments/runtime-requirements).
Loading