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.

Suspense is not resolved and the requests are looping

See original GitHub issue
import React, { Suspense } from 'react';
import useSWR from '@zeit/swr'

function StarWarsSuspense() {
  return (
    <Suspense fallback={<div>loading ...</div>}>
      <StarWars />
    </Suspense>
  )
}

function StarWars() {
  const { data } = useSWR('http://swquotesapi.digitaljedi.dk/api/SWQuote/RandomStarWarsQuote', fetch, { suspense: true });

  return (
    <div>
      {data.starWarsQuote}
    </div>
  );
}

export default StarWarsSuspense;

With this code, i never get the final component, the placeholder stay forever, looking on chrome developer console, the requests are looping.

I made this code using the readme example, i tried change de fetch function to a random promise to see if i get out of fallback, without no results.

I doing something wrong or this is really something that should not happen ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
shudingcommented, Oct 31, 2019

@erikjung sorry that PR wasn’t included in 0.1.2.
Updating to swr@0.1.5 will fix it:

https://codesandbox.io/s/swr-playground-946db

2reactions
erikjungcommented, Oct 30, 2019

I also get the same outcome: https://codesandbox.io/s/lucid-field-kbz20

Not sure if the suspense option is intended for the existing suspense feature in React stable or for the new concurrent functionality of react@experimental. Tried both approaches with both versions of React and got the same results.

Also unclear if anything special is required for the fetch function implementation. The docs imply that passing the global fetch function directly should work, but this basic example is wrapping fetch to resolve the .json() promise as well. 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suspense is not resolved and the requests are looping #46
I made this code using the readme example, i tried change de fetch function to a random promise to see if i get...
Read more >
Suspense for Data Fetching (Experimental) - React
Suspense is not a data fetching library. It's a mechanism for data fetching libraries to communicate to React that the data a component...
Read more >
React Suspense makes network waterfall when a component ...
I know that Suspense catches a Promise and shows Loading fallback until it is settled. So I understand why it make waterfall. Then,...
Read more >
React Suspense: Lessons Learned While Loading Data
The asynchronous nature of data loading means each of these requests can be returned in any order.
Read more >
useState with Suspense causes rerender loop? : r/reactjs
I have an issues though where useState keeps invoking the initial function passed into it, therefore rerendering the component. I have no idea ......
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