Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Use SWR's fallbackData #44

Merged
merged 1 commit into from
Jun 9, 2022
Merged

Use SWR's fallbackData #44

merged 1 commit into from
Jun 9, 2022

Conversation

shuding
Copy link
Contributor

@shuding shuding commented Jun 9, 2022

Currently on the server side, the fetcher data is provided to SWR via a customized fetcher ((id) => ast || twitter.tweetAstMap[id] || twitter.swrOptions.fetcher(id)). However SWR will not start data fetching on the server so the returned result will always be undefined.

Because of that, the SSR result and the initial render (hydration) will be empty. And then it fetches the data and immediately return and render the provided data. Hence we have the #5 issue.

In this PR we upgrade SWR to the latest stable version and use the fallbackData field to provide the SSR'd data to SWR. With this SWR doesn't need to fetch on the server side but can also return the value as a fallback. Docs can be found in https://swr.vercel.app/docs/prefetching#pre-fill-data.

Closes #5.

@vercel
Copy link

vercel bot commented Jun 9, 2022

Someone is attempting to deploy a commit to a Personal Account owned by @transitive-bullshit on Vercel.

@transitive-bullshit first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-static-tweets ❌ Failed (Inspect) Jun 9, 2022 at 4:25PM (UTC)

@transitive-bullshit transitive-bullshit merged commit ff61986 into transitive-bullshit:master Jun 9, 2022
@transitive-bullshit
Copy link
Owner

Thanks so much @shuding 🙏

I will follow-up by fixing the example build failure and getting an updated release out shortly.

@transitive-bullshit
Copy link
Owner

Successfully published:

@rauchg
Copy link

rauchg commented Jun 9, 2022

You're the 🐐s @shuding and @transitive-bullshit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix layout shift with SSR
3 participants