-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve runtime performance of
useTranslations
by avoiding th…
…e creation of message format instances if possible and introducing a cross-component message format cache (#475) Fixes #294
- Loading branch information
Showing
8 changed files
with
240 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// eslint-disable-next-line import/no-named-as-default -- False positive | ||
import type IntlMessageFormat from 'intl-messageformat'; | ||
|
||
type MessageFormatCache = Map< | ||
/** Format: `${locale}.${namespace}.${key}.${message}` */ | ||
string, | ||
IntlMessageFormat | ||
>; | ||
|
||
export default MessageFormatCache; |
1 change: 1 addition & 0 deletions
1
packages/use-intl/src/core/convertFormatsToIntlMessageFormat.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import {createContext} from 'react'; | ||
import {InitializedIntlConfig} from '../core/IntlConfig'; | ||
import MessageFormatCache from '../core/MessageFormatCache'; | ||
|
||
const IntlContext = createContext<InitializedIntlConfig | undefined>(undefined); | ||
const IntlContext = createContext< | ||
| (InitializedIntlConfig & { | ||
messageFormatCache?: MessageFormatCache; | ||
}) | ||
| undefined | ||
>(undefined); | ||
|
||
export default IntlContext; |
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
Oops, something went wrong.
4d177f8
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-next-13 – ./examples/example-next-13
next-intl-example-next-13-next-intl.vercel.app
next-intl-example-next-13.vercel.app
next-intl-example-next-13-git-main-next-intl.vercel.app
4d177f8
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:
example-next-13-next-auth – ./examples/example-next-13-next-auth
example-next-13-next-auth-next-intl.vercel.app
example-next-13-next-auth.vercel.app
example-next-13-next-auth-git-main-next-intl.vercel.app
4d177f8
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.vercel.app
next-intl-docs-next-intl.vercel.app
next-intl-docs-git-main-next-intl.vercel.app