Skip to content

Conversation

@Akcthecoder200
Copy link

#The Problem(#1305)
LingoProvider was showing a blank screen while the dictionary loaded because it returned null during loading. There were even TODO comments in the code suggesting Suspense should handle this, but it wasn't implemented. This created a poor user experience, especially on slower connections.

#The Solution
We implemented proper React Suspense support in LingoProviderWrapper:

#Key Changes:
Replaced the old pattern - Instead of using useState/useEffect and returning null, we now throw promises to trigger Suspense
Added a default loading UI - Created a DefaultLoadingFallback component with a spinner and "Loading translations..." text
Made it customizable - Added an optional fallback prop so developers can provide custom loading UI
Implemented caching - Dictionary and loading promises are cached to avoid redundant requests

#How it works:
When loading starts, the component throws a promise
React's Suspense catches it and shows the fallback UI
When the promise resolves, the dictionary is cached
On re-render, the cached dictionary is used and children render normally

#Benefits
✅ Users see a professional loading spinner instead of a blank screen
✅ Follows modern React patterns with Suspense
✅ Backwards compatible - existing code works without changes
✅ Customizable fallback UI
✅ All tests pass (73/73)

#Files Changed
provider.tsx - Main implementation with Suspense
provider.spec.tsx - Updated tests

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot finished reviewing on behalf of maxprilutskiy November 24, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant