-
-
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: Don't retrieve defaults for
locale
, now
and timeZone
if th…
…ese options have been provided to `NextIntlClientProvider` (#633) Fixes #631 See corresponding section in the release notes: [Changes to `NextIntlClientProvider`](https://next-intl-docs.vercel.app/blog/next-intl-3-0#changes-to-nextintlclientprovider) (once this PR is merged)
- Loading branch information
Showing
6 changed files
with
98 additions
and
27 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
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
18 changes: 7 additions & 11 deletions
18
packages/next-intl/src/react-server/NextIntlClientProvider.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
53 changes: 53 additions & 0 deletions
53
packages/next-intl/test/react-server/NextIntlClientProvider.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,53 @@ | ||
import {expect, it, vi} from 'vitest'; | ||
import NextIntlClientProvider from '../../src/react-server/NextIntlClientProvider'; | ||
import {getLocale, getNow, getTimeZone} from '../../src/server'; | ||
import BaseNextIntlClientProvider from '../../src/shared/NextIntlClientProvider'; | ||
|
||
vi.mock('../../src/server', async () => ({ | ||
getLocale: vi.fn(async () => 'en-US'), | ||
getNow: vi.fn(async () => new Date('2020-01-01T00:00:00.000Z')), | ||
getTimeZone: vi.fn(async () => 'America/New_York') | ||
})); | ||
|
||
vi.mock('../../src/shared/NextIntlClientProvider', async () => ({ | ||
default: vi.fn(() => 'NextIntlClientProvider') | ||
})); | ||
|
||
it("doesn't read from headers if all relevant configuration is passed", async () => { | ||
const result = await NextIntlClientProvider({ | ||
children: null, | ||
locale: 'en-GB', | ||
now: new Date('2020-02-01T00:00:00.000Z'), | ||
timeZone: 'Europe/London' | ||
}); | ||
|
||
expect(result.type).toBe(BaseNextIntlClientProvider); | ||
expect(result.props).toEqual({ | ||
children: null, | ||
locale: 'en-GB', | ||
now: new Date('2020-02-01T00:00:00.000Z'), | ||
timeZone: 'Europe/London' | ||
}); | ||
|
||
expect(getLocale).not.toHaveBeenCalled(); | ||
expect(getNow).not.toHaveBeenCalled(); | ||
expect(getTimeZone).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('reads missing configuration from getter functions', async () => { | ||
const result = await NextIntlClientProvider({ | ||
children: null | ||
}); | ||
|
||
expect(result.type).toBe(BaseNextIntlClientProvider); | ||
expect(result.props).toEqual({ | ||
children: null, | ||
locale: 'en-US', | ||
now: new Date('2020-01-01T00:00:00.000Z'), | ||
timeZone: 'America/New_York' | ||
}); | ||
|
||
expect(getLocale).toHaveBeenCalled(); | ||
expect(getNow).toHaveBeenCalled(); | ||
expect(getTimeZone).toHaveBeenCalled(); | ||
}); |
824363a
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.vercel.app
next-intl-example-app-router-next-intl.vercel.app
next-intl-example-app-router-git-main-next-intl.vercel.app
next-intl-example-next-13.vercel.app
824363a
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-git-main-next-intl.vercel.app
next-intl-docs.vercel.app
next-intl-docs-next-intl.vercel.app