惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
博客园 - 司徒正美
博客园 - 叶小钗
T
Tailwind CSS Blog
博客园 - Franky
V
V2EX
有赞技术团队
有赞技术团队
美团技术团队
雷峰网
雷峰网
爱范儿
爱范儿
Jina AI
Jina AI
D
DataBreaches.Net
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Why Your Nextjs UI Flickers: TanStack Query vs useEffect
nishchal sin · 2026-05-13 · via DEV Community

A page can load quickly and still feel unstable.

That usually happens when the initial render strategy is fine, but client-side data updates are handled poorly.

In this article, we’ll compare two common approaches:

  • A basic useEffect fetch
  • A production-ready pattern using TanStack Query

Both fetch the same API under the same network conditions.

One flickers.

The other stays smooth.


Overview of how TanStack Query keeps previous data visible while naive useEffect fetching causes UI flicker in Next.js


The Experiment

I built a small Next.js Rendering Lab to visualize:

  • SSR
  • CSR
  • SSG
  • ISR
  • Hydration
  • Cached background refetching
  • UI flicker caused by naive fetching

Both components:

  • call the same endpoint
  • refetch every few seconds
  • run under throttled network conditions
  • display live telemetry

Naive useEffect Fetching

A common pattern looks like this:

useEffect(() => {
  setLoading(true);

  fetch("/api/data")
    .then((res) => res.json())
    .then((data) => {
      setData(data);
      setLoading(false);
    });
}, []);

Enter fullscreen mode Exit fullscreen mode

This works, but on every refetch:

  • loading state resets
  • content disappears
  • layout shifts
  • charts blink

The data may arrive quickly, but the interface feels unstable.


TanStack Query

TanStack Query handles updates differently.

It:

  • keeps previous data visible
  • fetches in the background
  • updates only changed values
  • avoids unnecessary loading states

The result is a much smoother experience.

Users continue seeing the existing UI while fresh data is being fetched.


Side-by-side comparison of TanStack Query cached background refetching versus useEffect loading and UI resets


Rendering Strategy vs Data Strategy

These are two separate concerns.

Rendering Strategy

Determines how the page initially loads.

  • SSR
  • SSG
  • ISR
  • CSR

Data Strategy

Determines how the UI behaves after hydration.

  • useEffect
  • TanStack Query
  • SWR
  • caching
  • background refetching

A page can be server-rendered and still flicker if data updates are handled poorly.


Diagram showing the difference between Next.js rendering strategies like SSR and CSR and data strategies like TanStack Query


Why This Matters

This becomes obvious in:

  • dashboards
  • analytics tools
  • admin panels
  • live metrics
  • stock tickers
  • collaborative applications

Users may not understand hydration or caching, but they notice:

  • flicker
  • disappearing content
  • layout shifts
  • unstable interfaces

Good frontend UX is often about preserving visual stability.


Try the Rendering Lab

Live Demo:
Next.js Rendering Lab

Source Code:
GitHub Repository


Watch the YouTube Short

I also recorded a short visual comparison showing both patterns side by side under Slow 4G throttling.


Final Thoughts

The biggest lesson from this experiment:

Performance is not only about speed. It is also about stability.

Two apps can fetch data at almost the same speed but feel completely different depending on how updates are handled.

TanStack Query does not make your API faster.

It makes your UI behave better.

And users notice that immediately.