nextjs - 💡(How to fix) Fix Loading state shown on SSR despite all required data being prefetched [10 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87534Fetched 2026-04-08 02:06:51
View on GitHub
Comments
10
Participants
2
Timeline
13
Reactions
0
Timeline (top)
commented ×10issue_type_added ×1labeled ×1subscribed ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.22.0
Relevant Packages:
  next: 16.1.0 // Latest available version is detected (16.1.0).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/TrevorBurnham/nextjs-loading-flicker-repro

To Reproduce

  1. Create a page.tsx and a loading.tsx in the App Router
  2. Prefetch data in page.tsx and use that data to populate the TanStack Query cache
  3. Use TanStack Query's useSuspenseQuery to consume that data
  4. Load the page in the browser

Current vs. Expected behavior

I'd expect the full contents of the page to be shown immediately with no loading state since all data required by the page is prefetched (that is, the TanStack Query cache is already populated with the data it consumes).

Instead, I'm seeing a flicker of loading state before I see the page contents.

Strangely, the page's HTML contains both the loading state and the actual page content, yet the page content is hidden until some JavaScript executes.

In my mind, this behavior defeats the seamless loading experience that's supposed to be one of the benefits of SSR. It feels like I'm facing a very harsh tradeoff: I can either use loading.tsx to have responsive navigation, or I can omit it to have fully functioning SSR.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.22.0
Relevant Packages:
  next: 16.1.0 // Latest available version is detected (16.1.0).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Loading UI and Streaming

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

extent analysis

TL;DR

  • The issue can be mitigated by re-examining the usage of useSuspenseQuery and ensuring that the prefetched data is correctly populated in the TanStack Query cache.

Guidance

  • Review the page.tsx and loading.tsx files to ensure that the data is being prefetched and cached correctly using TanStack Query.
  • Verify that the useSuspenseQuery hook is being used correctly to consume the cached data.
  • Check the HTML output to confirm that both the loading state and page content are being rendered, and investigate why the page content is initially hidden.
  • Consider exploring alternative approaches to achieve a seamless loading experience, such as using a different caching strategy or optimizing the rendering of the page content.

Example

  • No specific code example can be provided without further information, but reviewing the usage of useSuspenseQuery and the caching strategy in the page.tsx file may help identify the issue.

Notes

  • The issue may be related to the specific configuration of Next.js and TanStack Query, and further investigation is needed to determine the root cause.
  • The provided environment information and package versions may be relevant to the issue, but without more context, it is difficult to determine the exact cause.

Recommendation

  • Apply workaround: Re-examine the usage of useSuspenseQuery and the caching strategy to mitigate the issue, as the root cause is not immediately clear and may require further investigation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Loading state shown on SSR despite all required data being prefetched [10 comments, 2 participants]