Commit 15ed625
authored
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)
```
1 parent 20d39e6 commit 15ed625
File tree
10 files changed
+228
-170
lines changed- docs
- src
- components
- test
- perf
- unit/components
10 files changed
+228
-170
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | | - | |
| 419 | + | |
| 420 | + | |
420 | 421 | | |
421 | | - | |
422 | | - | |
| 422 | + | |
| 423 | + | |
423 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
424 | 429 | | |
425 | 430 | | |
426 | 431 | | |
| |||
439 | 444 | | |
440 | 445 | | |
441 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
442 | 461 | | |
443 | 462 | | |
444 | 463 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
243 | 272 | | |
244 | 273 | | |
245 | 274 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
| 67 | + | |
| 68 | + | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
0 commit comments