Implementing Data Polling with Stale Data in Next.js 14 using React Query
Hey everyone! 👋
Let's delve into a scenario:
In the app I'm developing, there's a flight details page designed to display real-time flight information. The challenge is that this data needs to be updated every few seconds.
Currently, my approach involves a server-side component that initially fetches the data and then passes it down to the flight details component on the client-side. Additionally, there's a
loading.tsx
component that displays a loading skeleton, as depicted in the images.
Let's review the code below:


1 Reply
environmental-roseOP•2y ago
Before proceeding, it's essential to acknowledge that I'm uncertain if this approach is feasible...
The Challenge:
I aim to have loading skeleton only during the server fetch for the initial data and employ SWR behavior for subsequent updates on the client-side. Essentially, I want the skeleton to appear only when the page loads for the first time and not while data is being updated in the background. This ensures the old data remains visible during the request, and once the new data is ready, it seamlessly replaces the old without causing layout shifts.