-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using `formatMessage` with `ReactElement` imperatively, e.g: ```tsx formatMessage('hello {world}', {world: <b>world</b>) // returns ['hello ', <b>world</b>] ``` New signature will be: ```ts formatMessage(msg: string, values: Record<string, string | number | null | undefined | React.ReactNode>): string[] | React.ReactNodeArray ``` Use case: - Right now the only way to format rich text is to use `FormattedMessage`, this brings feature-parity to the imperative version `formatMessage` as well. - `formatMessage` is also faster and doesn't create extra React Node. - Also remove the need to regen UUID for every rich text token in `FormattedMessage`, which improves perf as well Before: ``` 100 x <FormattedMessage> with placeholder x 76.83 ops/sec ±9.83% (69 runs sampled) 100 x <FormattedMessage> with placeholder in AST form x 206 ops/sec ±1.12% (79 runs sampled) 100 x <FormattedMessage> with placeholder, cached x 573 ops/sec ±1.07% (84 runs sampled) 100 x <FormattedMessage> with placeholder, cached in AST form x 392 ops/sec ±4.28% (82 runs sampled) ``` After: ``` 100 x <FormattedMessage> with placeholder x 85.51 ops/sec ±3.66% (66 runs sampled) 100 x <FormattedMessage> with placeholder in AST form x 210 ops/sec ±2.27% (76 runs sampled) 100 x <FormattedMessage> with placeholder, cached x 619 ops/sec ±2.00% (87 runs sampled) 100 x <FormattedMessage> with placeholder, cached in AST form x 426 ops/sec ±1.61% (84 runs sampled) ```
- Loading branch information
Showing
10 changed files
with
228 additions
and
170 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.