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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
B
Blog
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
I
InfoQ
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
H
Help Net Security

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
Stop Crashing the Browser: Server-Side Data Grids in Next...
Prajapati Pa · 2026-05-20 · via DEV Community

The Client-Side Fetching Disaster

Data tables are the most common UI element in any B2B SaaS dashboard. When tasked with building a "Client Roster" grid, many React developers reach for heavy client-side libraries. They fetch all 5,000 client records from the API, store them in a massive useState array, and let the browser's JavaScript engine handle the sorting, filtering, and pagination.

For 100 rows, this is blazing fast. For 50,000 rows, this architecture is a disaster. You force the user to download a 5MB JSON payload. Their browser tab consumes massive amounts of RAM, the UI stutters during sorting, and mobile devices completely crash. At Smart Tech Devs, we never send unnecessary data to the client. We architect Server-Side Data Grids using Next.js Server Components.

The Architecture: URL-Driven Server Components

To build a high-performance grid, the database must do the heavy lifting. The frontend's only job is to update the URL parameters. The Next.js Server Component reads those parameters, executes a highly optimized SQL query (with LIMIT and OFFSET), and sends exactly 10 rows of pure HTML to the browser.

Step 1: The Server Component Core

In the Next.js App Router, the page.tsx automatically receives the searchParams from the URL. We pass these directly to our database fetcher.


// app/dashboard/clients/page.tsx
import { Suspense } from 'react';
import db from '@/lib/db';
import ClientTable from './components/ClientTable';
import TableSkeleton from './components/TableSkeleton';

export default async function ClientsPage({
    searchParams,
}: {
    searchParams: { q?: string; sort?: string; page?: string };
}) {
    // 1. Extract URL state with safe defaults
    const query = searchParams?.q || '';
    const sort = searchParams?.sort || 'created_at_desc';
    const currentPage = Number(searchParams?.page) || 1;
    const perPage = 10;

    // 2. Perform the heavy lifting securely on the server
    const clients = await db.client.findMany({
        where: {
            name: { contains: query, mode: 'insensitive' },
        },
        orderBy: {
            [sort.split('_')[0]]: sort.split('_')[1], // e.g., created_at: 'desc'
        },
        skip: (currentPage - 1) * perPage,
        take: perPage,
    });

    const totalCount = await db.client.count({
        where: { name: { contains: query, mode: 'insensitive' } }
    });

    return (
        <main>
            <h1>Client Roster</h1>
            <Suspense fallback={<TableSkeleton />}>
                {/* We pass ONLY the 10 rows of data to the UI component */}
                <ClientTable data={clients} totalPages={Math.ceil(totalCount / perPage)} />
            </Suspense>
        </main>
    );
}

Step 2: The Client Component UI

The ClientTable component doesn't need to know how to sort data. It just needs to update the browser URL when a user clicks a column header. Next.js will automatically re-run the Server Component and stream the new rows in.


// app/dashboard/clients/components/ClientTable.tsx
"use client";

import { useRouter, usePathname, useSearchParams } from 'next/navigation';

export default function ClientTable({ data, totalPages }) {
    const router = useRouter();
    const pathname = usePathname();
    const searchParams = useSearchParams();

    const handleSort = (column: string) => {
        const params = new URLSearchParams(searchParams);
        
        // Toggle sort direction
        const currentSort = params.get('sort');
        const newSort = currentSort === `${column}_asc` ? `${column}_desc` : `${column}_asc`;
        
        params.set('sort', newSort);
        router.push(`${pathname}?${params.toString()}`);
    };

    return (
        <table className="w-full">
            <thead>
                <tr>
                    <th onClick={() => handleSort('name')} className="cursor-pointer">Name ↕</th>
                    <th onClick={() => handleSort('status')} className="cursor-pointer">Status ↕</th>
                </tr>
            </thead>
            <tbody>
                {data.map(client => (
                    <tr key={client.id}>
                        <td>{client.name}</td>
                        <td>{client.status}</td>
                    </tr>
                ))}
            </tbody>
        </table>
    );
}

The Engineering ROI

By keeping data grids server-side, you completely decouple your frontend performance from the size of your database. Whether your client has 100 customers or 10 million, the browser only ever downloads exactly 10 rows of data. This guarantees a blazing-fast, crash-proof user experience on any device.