Commit b828bf0
authored
fix(tldraw): export TldrawUiTranslationProvider and dedupe missing-translation warning (tldraw#8909)
In order to let consumers render components like
`TldrawSelectionForeground` without pulling in the full
`TldrawUiContextProvider` (and its icon preloading), this PR promotes
`TldrawUiTranslationProvider`, `AssetUrlsProvider`, and `useAssetUrls`
from `@internal` to `@public`. It also deduplicates the "No translation
messages found" warning so it only logs once per session instead of once
per component that calls `useTranslation`, and rewords the message to
point developers at `TldrawUiTranslationProvider` as an alternative.
Closes tldraw#6236
Consumers can now do:
```tsx
<AssetUrlsProvider assetUrls={...}>
<TldrawUiTranslationProvider locale="en">
<TldrawSelectionForeground ... />
</TldrawUiTranslationProvider>
</AssetUrlsProvider>
```
### Change type
- [x] `bugfix`
### Test plan
1. Render a component that uses `useTranslation` (e.g.
`TldrawSelectionForeground`) outside of `TldrawUiContextProvider`.
2. Confirm the "No translation messages found" warning prints **once**,
not once per consumer.
3. Wrap the same component in
`<AssetUrlsProvider><TldrawUiTranslationProvider locale="en">` and
confirm the warning is silenced and translations resolve.
- [ ] Unit tests
- [ ] End to end tests
### Release notes
- Export `TldrawUiTranslationProvider`, `AssetUrlsProvider`, and
`useAssetUrls` as public API so `TldrawSelectionForeground` and similar
components can be used without `TldrawUiContextProvider`.
- Only log the missing-translation warning once per session instead of
once per `useTranslation` consumer.
### API changes
- Changed `TldrawUiTranslationProvider` from `@internal` to `@public
@react`.
- Changed `AssetUrlsProvider` from `@internal` to `@public @react`.
- Changed `useAssetUrls` from `@internal` to `@public`.
### Code changes
| Section | LOC change |
| --------------- | ---------- |
| Core code | +18 / -6 |
| Automated files | +3 / -3 |1 parent 6dbd8b4 commit b828bf0
3 files changed
Lines changed: 18 additions & 8 deletions
File tree
- packages/tldraw
- src/lib/ui
- context
- hooks/useTranslation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
| 481 | + | |
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
| |||
4364 | 4364 | | |
4365 | 4365 | | |
4366 | 4366 | | |
4367 | | - | |
| 4367 | + | |
4368 | 4368 | | |
4369 | 4369 | | |
4370 | 4370 | | |
| |||
6309 | 6309 | | |
6310 | 6310 | | |
6311 | 6311 | | |
6312 | | - | |
| 6312 | + | |
6313 | 6313 | | |
6314 | 6314 | | |
6315 | 6315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| |||
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
40 | | - | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
| |||
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
40 | 43 | | |
41 | | - | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
0 commit comments