-
Notifications
You must be signed in to change notification settings - Fork 668
feat(react): add Suspense fallback to LingoProviderWrapper #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react): add Suspense fallback to LingoProviderWrapper #1534
Conversation
|
Hey @verma-divyanshu-git please link the issue this will solve and only raise a PR after being assigned to an issue. |
|
please update base, it is out of date |
|
@verma-divyanshu-git you need to update the title: Error: No release type found in pull request title " Add Suspense fallback to LingoProviderWrapper". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/ Available types:
|
|
And also make sure you're added changeset |
|
I'd like to review this at some point, if that's okay. If I don't review it within 24 hours and you need to merge it, just merge it. |
95a7b09 to
0500fad
Compare
|
hey, @sumitsaurabh927, @The-Best-Codes , I have made all the changes, sorry for the trouble |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces breaking changes. The documentation would also need to be updated (which only the team can do), the AdonisJS demo would likely break, and users may have to make changes to their code.
Because of this, I think feedback from the team is necessary (it might be better if the team made a change like this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the feedback! This doesn't break anything, existing code keeps working as is. The only change users see is a loading message instead of blank screen while the dictionary loads.
The fallback prop is optional. If you don't pass it, you get the default. If you pass null, you get the old behavior (no UI during load).
I added this because of the TODO comments in the code. If you'd rather handle it differently or want to discuss the approach first, just let me know and I can close this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah to me it looks like error handling will be different now because of the Suspense but I'll test it locally. Give me a sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the Vite and Next.js demos locally and they seem to be working fine. I can't test the AdonisJS one right now... but I think it will be okay ✔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! AdonisJS uses the same client provider so should be fine, but let me know if you want me to verify anything specific.
|
One thing I notice: I can't remove the fallback. Setting it to |
|
@The-Best-Codes , Sorry, my bad. The Should I change it so the fallback defaults to |
|
@verma-divyanshu-git Yes, I think that would be best. |
491093e to
60d5ff7
Compare
|
@The-Best-Codes , Done! Fallback now defaults to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, haven't tested locally yet but I think it will work fine!
Let's wait to see what the team thinks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds React Suspense support to LingoProviderWrapper to display a loading UI instead of returning null during dictionary loading, improving user experience especially on slower connections.
Key changes:
- Replaced
useState/useEffectpattern with Suspense boundary and resource pattern for dictionary loading - Added
LingoProviderFallbackcomponent with accessible ARIA attributes as default loading UI - Added optional
fallbackprop to allow custom loading UI
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/react/src/client/provider.tsx | Implements Suspense pattern with createDictionaryResource, adds DictionaryBoundary component, and exports LingoProviderFallback |
| packages/react/src/client/provider.spec.tsx | Updates tests to verify Suspense behavior, custom fallback support, and error boundary propagation |
| demo/vite-project/src/main.tsx | Demonstrates new API by importing and using LingoProviderFallback |
| .changeset/suspense-fallback.md | Documents the feature as a minor version bump |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const resource = useMemo( | ||
| () => | ||
| createDictionaryResource({ | ||
| load: () => props.loadDictionary(locale), | ||
| locale, | ||
| }), | ||
| [props.loadDictionary, locale], |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resource will be recreated whenever props.loadDictionary changes identity (e.g., on parent re-renders if an inline arrow function is passed). This causes the dictionary to reload unnecessarily. The dependency array should likely only include locale, or the function reference should be stabilized with useCallback in the calling code. Consider adding a comment documenting that loadDictionary should be stable, or use useRef to store the load function and only recreate the resource when locale changes.
What
Adds Suspense support to
LingoProviderWrapperso it shows a loading UI instead of a blank screen while the dictionary loads.Why
Closes #1305
Right now
LingoProviderWrapperreturnsnullduring dictionary load, which causes a jarring blank screen. This is especially noticeable on slower connections or when loading remote dictionaries.How
LingoProviderFallbackcomponent as the default loading UI (accessible with proper ARIA attributes)fallbackprop so teams can provide custom loading UITesting
pnpm --filter @lingo.dev/_react test- all 74 tests pass