question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying not to use suspense, getting suspense errors

See original GitHub issue

Hi! Due to specific project constraints, I would like to handle the loading state of the translations as far down as I can, with minimum refactoring.

I previously had a <Suspense> component wrapping my application, but getting a proper fallback was difficult, and I had loaders when loading a new namespace, breaking my layout.

I chose to override my withTranslation / useTranslation imports for minimal refactoring, replacing them with essentially the same thing, but with their loader inside the t() call.

Code is available here:

I initially tried to wrap my CustomT with a <Suspense> component, but since it was called below useTranslation it wasn’t working. I chose to opt-out of suspense by using useSuspense: false in each useTranslation usage, and set useSuspense to false in the i18n configuration

With everything set to false, I removed the root <Suspense> component, checked that no useTranslation and withTranslation were imported straight from react-i18n and still got a suspense error:

Error: A React component suspended while rendering, but no fallback UI was specified. Add a <Suspense fallback=...> component higher in the tree to provide a loading indicator or placeholder to display. in Unknown (at withTracker.js:36) in HOC (created by Context.Consumer) in Route (at Body.js:143) in Switch (at Body.js:142) in main (created by Context.Consumer) in Styled(main) (at Body.js:125) in Query (at Body.js:109) in Body (created by I18nextWithTranslation) in I18nextWithTranslation (created by Context.Consumer) in withRouter(I18nextWithTranslation) (at src/index.js:68) in SentryReporter (created by I18nextWithTranslation) in I18nextWithTranslation (created by Context.Consumer) in withRouter(I18nextWithTranslation) (at src/index.js:67) in Router (at src/index.js:65) in ApolloProvider (at src/index.js:64)

Any pointers?

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Aldriancommented, May 6, 2020

You were right. I checked for all imports, and it ended up being a React.lazy() component defined somewhere in the tree that was needing suspense.

Sorry for the trouble!

0reactions
jamuhlcommented, May 6, 2020

And what I guess…you missed somewhere animport { useTranslation } from 'react-i18next'

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suspense for Data Fetching (Experimental) - React
Approach 1: Fetch-on-Render (not using Suspense). A common way to fetch data in React apps today is to use an effect: // In...
Read more >
Catch Your Suspense Errors - chan.dev
Catch Your Suspense Errors. Not every promise resolves. Some are rejected. So, when we use React.Suspense to show loading and loaded states,
Read more >
All You Need To Know About React Suspense - CopyCat Blog
In this article, we're going to explore what is a React Suspense, a React Suspense Fallback UI, and how to use them in...
Read more >
10 Minute Read: Understanding React Suspense with Visuals ...
In a sentence, React Suspense lets you handle loading states in your application in an idiomatic, React-y, sorta magical way.
Read more >
What Is a Suspense Account? | Examples and How to Use
In accounting, it's not always clear which account you should post an entry in. Use a suspense account to hold these transactions until ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found