Uh oh!
There was an error while loading. Please reload this page.
fix(i18n): drop try/catch-around-hook in createSafeTranslation / useSafeTranslate - #2605
Merged
Conversation
…afeTranslate The last known rules-of-hooks violation of the class fixed in #2595/#2596 — the factory closure escaped the static lint, but the runtime risk is the same: a throw after useObjectTranslation ran would desync hook order on the next render. The hook is provider-safe, and the real fallback behavior is carried by the testKey probe (createSafeTranslation) and per-key t(key) === key detection (useSafeTranslate), both unchanged and now locked by tests (no-provider defaults, placeholder interpolation, key-chain form). The fallback t is now a stable per-factory reference, so downstream memo deps stop invalidating every render in the no-translations case. Verification: vitest i18n + plugin-detail + fields 656 ✓; eslint 0 errors; turbo type-check @object-ui/i18n ✓. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016wpaFMPowSn4nAWsjeGZib
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
os-zhuang
marked this pull request as ready for review
July 16, 2026 13:41
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or 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
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The last known rules-of-hooks violation of the class fixed in #2595/#2596:
@object-ui/i18n'screateSafeTranslation(the factory underuseDetailTranslation,useFieldTranslation, form/filter/sort builders, MetricWidget, ModalForm…) and its siblinguseSafeTranslatewrappeduseObjectTranslation()in try/catch inside the returned hook. The factory closure escapes eslint's static detection, but the runtime risk is identical — a throw after the hook ran would desync hook order on the next render.useObjectTranslationis provider-safe (optional context read + react-i18next global-instance fallback), so the guard is removed. The real fallback behavior is unchanged and now test-locked:createSafeTranslation: the testKey probe still returns the English defaults map (with{{placeholder}}interpolation) when translations aren't configured;useSafeTranslate: per-keyt(key) === keydetection still returns the call-site fallback, key-chain form included.Bonus: the fallback
tis now a stable per-factory reference (previously a fresh closure every render), so downstreamuseMemo/useCallbackdeps stop invalidating every render in the no-translations case — the same stability concern ListView documented for its old module-level fallback.Verification
useSafeTranslation.test.tsx: no-provider defaults, placeholder interpolation, unknown-key passthrough, stable-reference across renders, key-chain fallbackturbo run type-check@object-ui/i18n ✓Refs #2595 / #2596 (completes the hooks-violation sweep — no known instances remain).
🤖 Generated with Claude Code
https://claude.ai/code/session_016wpaFMPowSn4nAWsjeGZib
Generated by Claude Code