fix(transloco): avoid duplicate fallback lang request when already cached#912
fix(transloco): avoid duplicate fallback lang request when already cached#912arturovt wants to merge 1 commit into
Conversation
…ched When `useFallbackTranslation` is enabled, loading a secondary language (e.g. 'es') would internally call `getFallbacksLoaders`, which invokes `resolveLoader` directly — bypassing the service cache. This caused a duplicate HTTP request for the fallback lang whenever it had already been fetched (e.g. as the default lang). Fix: before delegating to `getFallbacksLoaders`, check whether the fallback lang's observable is already in the cache. If it is, reuse it via a mapped `forkJoin` instead of issuing a new network request. Adds a regression test covering the case where `fallbackLang` matches `defaultLang` and a second language is loaded afterward.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughModified Changes
Suggested reviewers
Fun fact: Did you know? In i18n, fallback languages follow a cascade pattern—if a translation isn't available in the requested language, the system gracefully falls back to alternatives. This is why many apps default to English as the ultimate fallback. In Portuguese, the word "idioma" means language! 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@jsverse/transloco
@jsverse/transloco-locale
@jsverse/transloco-messageformat
@jsverse/transloco-optimize
@jsverse/transloco-persist-lang
@jsverse/transloco-persist-translations
@jsverse/transloco-preload-langs
@jsverse/transloco-schematics
@jsverse/transloco-scoped-libs
@jsverse/transloco-utils
@jsverse/transloco-validator
commit: |
When
useFallbackTranslationis enabled, loading a secondary language (e.g. 'es') would internally callgetFallbacksLoaders, which invokesresolveLoaderdirectly — bypassing the service cache. This caused a duplicate HTTP request for the fallback lang whenever it had already been fetched (e.g. as the default lang).Fix: before delegating to
getFallbacksLoaders, check whether the fallback lang's observable is already in the cache. If it is, reuse it via a mappedforkJoininstead of issuing a new network request.Adds a regression test covering the case where
fallbackLangmatchesdefaultLangand a second language is loaded afterward.Closes #625
PR Checklist
PR Type
Does this PR introduce a breaking change?
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests