Skip to content

fix(prompts): consolidate the page's first load into one server action - #473

Merged
gkhngyk merged 1 commit into
mainfrom
fix/prompts-page-first-load
Jul 18, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/prompts-page-first-load

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

The Prompts page's cold load was slow (reported as a minutes-long spinner). Next.js queues client-fired server actions sequentially — each is its own POST — and the page fired three on mount (volumes + prompt sets + visibility summaries) with the suggestions card's fourth queued behind them: the total wait was the SUM of all of them. This is the #313 lesson from Insights, never applied here.

Note: during debugging we also found the local dev slowness had a second, environment-side component (a corrupted .next incremental cache after heavy branch switching — fixed by rm -rf web/.next). The changes here address the real product-side costs and are what production users feel.

Related issue

No open issue — urgent fix requested directly; supersedes the client-side symptoms investigated on the Prompts page.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Cold-open /dashboard/prompts in a fresh tab: the table loads in a single round trip (one action POST in the Network tab instead of three serialized ones).
  2. Health columns (visibility/mentions/runs/last run) on a brand with >1000 results in 30 days now reflect the full window.
  3. Stop the aeo-server and reload: the prompt table still renders, with a "Volume data is temporarily unavailable" toast; volumes return after the server is back.
  4. Suggestions card, CSV export, volume analysis buttons and the Insights tab behave as before.

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

The Prompts page's cold load was slow because Next.js queues client-fired
server actions sequentially — each is its own POST — and the page fired
three (volumes + prompt sets + visibility summaries) with the suggestions
card's fourth queued behind them: total wait was the SUM of all of them
(the #313 lesson from Insights, never applied here).

- New getPromptsPageData action runs the three reads in a real
  server-side Promise.all — one round trip. A volumes failure/timeout
  degrades to an empty list with a warning toast instead of blanking the
  prompt table: the page's core content is never hostage to the volumes
  upstream.
- Visibility summaries move to a prompt_visibility_summaries RPC
  (migration 00025, SECURITY INVOKER): one GROUP BY per brand instead of
  pulling the raw 30-day result window into JS — which was also silently
  capped at 1000 rows by PostgREST, so busy brands showed wrong health
  columns (the #430/#464 defect family). Verified on production data:
  104 prompt rows, max 210 runs per prompt — depth the 1000-row sample
  could never see.
- The aeo-server fetches for volumes and the suggestions-card read get
  AbortSignal.timeout(15s) (#427 lesson) so a hung upstream can't pin
  the queue.

Fixes the reported slow/never-ending first load of /dashboard/prompts.
@gkhngyk
gkhngyk force-pushed the fix/prompts-page-first-load branch from 0da5536 to d1e8d33 Compare July 18, 2026 13:30
@gkhngyk
gkhngyk merged commit 8a82ec0 into main Jul 18, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the fix/prompts-page-first-load branch July 18, 2026 13:36
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.

1 participant