Skip to content

perf(citations): make Domains/URLs tab switching instant (keepMounted + memo) - #325

Merged
gkhngyk merged 1 commit into
mainfrom
feature/citations-tabs-keepmounted
Jun 30, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/citations-tabs-keepmounted

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Switching the Domains ↔ URLs tabs on the Citations page felt sluggish for brands with many cited domains/URLs. It's not a data fetch — both tables come from the same in-memory getCitationsOverview() result. The cost was unmount/re-mount: Base-UI's Tabs.Panel unmounts the inactive panel by default, so each switch destroyed one (uncapped) table and rebuilt the other from scratch.

Fix (web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx):

  1. keepMounted on the Domains/URLs TabsContent → both panels mount once and switching is a pure CSS visibility toggle (instant). Since the data is already fetched, this is a one-time render cost, not per-switch.
  2. React.memo around DomainsTable / UrlsTable → an unrelated parent re-render (e.g. filter state) doesn't re-render the whole table while its rows reference is unchanged.

No skeleton — the data is already loaded and the switch does no async work, so a skeleton would only flash an empty placeholder and make it feel worse.

web/src/components/ui/tabs.tsx needed no change: keepMounted already reaches Tabs.Panel via {...props} (confirmed by typecheck accepting it on TabsContent).

Related issue

Closes #299

Type of change

  • feat — New feature (performance)

How to test

  1. Open /dashboard/citations for a brand with many cited URLs.
  2. Switch Domains ↔ URLs repeatedly → instant, no visible render delay.
  3. DevTools/Network: no server action fires on tab switch (it already didn't).
  4. Changing filters still re-fetches and re-renders both tables correctly (no regression).

Notes

  • Optional future follow-up (out of scope): row virtualization for tabs that reach hundreds/thousands of rows.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

… + memo)

Tab switching does no async work — both tables are fed from the same
in-memory getCitationsOverview() result. The lag was unmount/re-mount:
Base-UI Tabs.Panel unmounts the inactive panel by default, so each switch
rebuilt the (uncapped) table from scratch.

- Pass keepMounted to the Domains/URLs TabsContent so both mount once and
  switching is a pure CSS visibility toggle.
- Wrap DomainsTable / UrlsTable in React.memo so an unrelated parent
  re-render (e.g. filter state) doesn't re-render the whole table when its
  rows reference is unchanged.

No skeleton (data is already loaded). tabs.tsx unchanged — keepMounted
reaches Tabs.Panel via {...props}.
@gkhngyk
gkhngyk merged commit 5976fc0 into main Jun 30, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feature/citations-tabs-keepmounted branch June 30, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant