-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow to call
getRequestConfig
in outer module closure in a Cl…
…ient Component module graph (#687) Fixes #685 This is fixed for compatibility, since we've silently supported this pattern previously. However, it's still not recommended to call `getRequestConfig` in a Client Component module graph as the function can't do anything useful there. Instead, you can extract shared config like `locales` to a file like [`src/navigation.ts`](https://next-intl-docs.vercel.app/docs/routing/navigation) or any other module that is then imported into Client and Server Components.
- Loading branch information
Showing
2 changed files
with
53 additions
and
8 deletions.
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
21 changes: 21 additions & 0 deletions
21
packages/next-intl/test/server/react-client/index.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {describe, expect, it} from 'vitest'; | ||
import {getRequestConfig} from '../../../src/server.react-client'; | ||
|
||
describe('getRequestConfig', () => { | ||
it('can be called in the outer module closure', () => { | ||
expect( | ||
getRequestConfig(({locale}) => ({ | ||
messages: {hello: 'Hello ' + locale} | ||
})) | ||
); | ||
}); | ||
|
||
it('can not call the returned function', () => { | ||
const getConfig = getRequestConfig(({locale}) => ({ | ||
messages: {hello: 'Hello ' + locale} | ||
})); | ||
expect(() => getConfig({locale: 'en'})).toThrow( | ||
'`getRequestConfig` is not supported in Client Components.' | ||
); | ||
}); | ||
}); |
0f16f10
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.
Successfully deployed to the following URLs:
next-intl-example-app-router – ./examples/example-app-router
next-intl-example-app-router-next-intl.vercel.app
next-intl-example-app-router.vercel.app
next-intl-example-app-router-git-main-next-intl.vercel.app
next-intl-example-next-13.vercel.app
0f16f10
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.
Successfully deployed to the following URLs:
next-intl-docs – ./docs
next-intl-docs-next-intl.vercel.app
next-intl-docs-git-main-next-intl.vercel.app
next-intl-docs.vercel.app