Skip to content

perf(citations): make Domains/URLs tab switching instant (keepMounted + memo, not a skeleton) #299

Closed

Description

@gkhngyk

Problem

Switching between the Domains and URLs tabs on the Citations page (/dashboard/citations) feels sluggish, especially for brands with many cited domains/URLs.

Root cause (it is NOT a data fetch)

Tab switching does not trigger any re-fetch. Both tabs are fed from a single getCitationsOverview() call whose result (data.rows + data.urlRows) is already in memory; the tabs only toggle which table is shown.

The lag is a re-mount + synchronous render cost:

  • The tabs use Base-UI's Tabs.Panel (web/src/components/ui/tabs.tsx), and the wrapper does not pass keepMounted. Base-UI unmounts the inactive panel by default, so every switch destroys the old table and mounts the other one from scratch.
  • The tables are uncapped: in web/src/lib/actions/citations.ts (~lines 300–336) rowsOut / urlRowsOut contain one row per distinct domain / URL with no limit. For a brand with many prompts × platforms, the URLs table can be hundreds of rows, so re-rendering it on each switch is expensive.

Why a skeleton is NOT the fix

A skeleton only helps while data is being awaited. Here the data is already loaded and tab switching does no async work — a skeleton would just flash an empty placeholder before the table renders, making the transition feel worse, not better. Please do not add a per-tab skeleton for this.

Proposed fix

  1. keepMounted — pass keepMounted to the TabsContent (Base-UI Tabs.Panel) for the Domains/URLs panels so both mount once and switching becomes a pure CSS visibility toggle (instant). The data is already fetched, so this is a one-time render cost, not per-switch.
  2. Memoize the tables — wrap DomainsTable / UrlsTable in React.memo so an unrelated parent re-render doesn't re-render the whole table.

Optional follow-up (separate, larger)

For brands where a tab reaches hundreds/thousands of rows, row virtualization (windowing) is the scalable fix. Out of scope for this issue — track separately if it proves necessary after 1+2.

Files to touch

  • web/src/components/ui/tabs.tsx — confirm keepMounted reaches Tabs.Panel via {...props} (it should), or expose it
  • web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx — pass keepMounted on the two TabsContent; wrap DomainsTable / UrlsTable in React.memo

How to test

  1. Open /dashboard/citations for a brand with a large number of cited URLs.
  2. Switch Domains ↔ URLs repeatedly — the switch is instant, with no visible render delay.
  3. Confirm in DevTools/Network that no server action fires on tab switch (it already doesn't).
  4. Filtering still re-fetches and re-renders both tables correctly (no regression).

Activity

  1. added
    enhancement
    good first issue
    on Jun 24, 2026
  2. self-assigned this
    on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions