-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Bug report
Description / Observed Behavior
What kind of issues did you encounter with SWR?
- Using SWR in an isomorphic application (Next.js + React)
- Regardless of conditionally calling the fetcher within useSWR, Im noticing my component render twice - even with reactstrictmode disabled
Expected Behavior
How did you expect SWR to behave here?
- I am simulating a fetch call on server side and passing this data down to an Age component
- Inside the Age component, useSWR will conditionally call the fetcher if the server did not pass in data
- As expected, the fetch call is not called on the client side - because the server data exists
- However, Im noticing that my component is rendering twice ie. notice the chrome dev tools logs happen twice in the sandbox - ive disabled react strict mode to remove re-render noise too
- All of the data returned from useSWR is still the same - so Im puzzled by the re-render
- When I do fetch calls using useEffect instead, my component only renders once
Repro Steps / Code Example
Or share your code snippet or a CodeSandbox link is also appreciated!
Relevant files:
app/page.tsxis the bulk of the pageapp/components/age-v2.tsxis the component that uses useSWRapp/utils/fetch-age.tsis a dummy promise to simulate a fetch request with wait timesnext.config.tsIve disabled reactstrictmode here to remove the bloated re-renders for debugging purposes
Additional Context
- Is this a misunderstanding I have of SWR? ie. is this expected behavior and if it is, why?
- Ive also seen a similar issue but I dont think the answer considered the server side use case Im presenting: UseSwr being called twice, i have done everything but fetched is called twice #1952
SWR version.
Add any other context about the problem here.
"dependencies": {
"next": "15.5.7",
"react": "19.0.0",
"react-dom": "19.0.0",
"swr": "2.3.8"
}

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels