Repository navigation
fix(prompts): Tracked Prompts loads in one read, volumes beside it and never missing on first load - #2483
Merged
Conversation
The table's read (getPromptsPageData) was a server action at the back of Next's queue: the menu's actions, then the page's getPromptTableViews, getContentUsage and getTrackingWindow went first, four round trips before the table on everyone's landing page. It now goes through POST /api/prompts/read, a fetch beside them, and brings the rest of the first view in its one Promise.all: the column views, the Improve links for every prompt (one brand-wide query, no read per page of rows), and Track now's prompts (one index probe per active prompt instead of the API's /tracking/unanalyzed, which read every active prompt's results and was cut at 1,000 rows). The volumes are their own fetch beside the rows, with the volume run's status, so the table never waits for the volumes API and a range change doesn't read them again. A failed volumes read is tried once more; until the volumes are in, their cells wait in place, the not-analyzed line isn't shown and Insights shows a skeleton, never "No volume data yet". Both reads drop an answer older than the latest. The Location filter reads its locations through /api/visibility/read, its place kept meanwhile, and the content quota is read once the rows are in. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
approved these changes
Nov 17, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good: same filters as the old /unanalyzed read, RLS-scoped, single-FK embeds. Minor: readBrandImprovingActions now applies MAX_ROWS = 1000 brand-wide, so on a brand with >1000 open Improve actions the oldest prompts lose their 'Improving' link.
This was referenced Nov 17, 2026
gkhngyk
pushed a commit
that referenced
this pull request
Nov 18, 2026
The page read getPromptVolumes as a server action with try/finally and no catch: a failed or timed-out read left the volumes empty and showed "No similar topics found." as if the brand had none. It now reads them as Tracked Prompts and Insights do (#2483): through /api/prompts/read (readPromptVolumes), one retry at once, a sequence guard so an older read never lands over a newer one, a skeleton of the cards and list while pending, and the same failure card with Retry. Shared from the Prompts page: the failure card (prompts/_volumes-failed.tsx, its two strings now in en.json) and VOLUME_READ_RETRIES (lib/prompts-reads.ts). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tracked Prompts: one read before the table, and volumes that don't go missing on first load
This PR fixes two problems on the Prompts page:
/dashboard/prompts/tracked, which became everyone's home in feat(nav): analytics before execution; everyone lands on Prompts › Tracked Prompts #2475, opens slowly.Problem 3 shares its code path with Problem 1 (
loadData→getPromptsPageData), so both are fixed here. (Problem 2, the Suggestions jump, and the summary line's wording and spacing are separate PRs.)Causes, by impact
The table's read waited at the back of Next's server-action queue. Next runs client-called server actions one at a time. React runs child effects before parent effects, so on mount the queue was:
markSeen('prompts/tracked'),getMenuState(dots),getSettingsState(managers), andmarkGettingStartedPageOpeneduntil it's recorded;AllPromptsTab'sgetPromptTableViews, thengetContentUsage(an API call with no timeout);useFirstRun'sgetTrackingWindow;PromptsPage'sgetPromptsPageData, the table itself;getBrandFilterOptionsandgetVolumeAnalysisStatus.That's 4 page-level sequential round trips before the table's data (6–8 counting the menu's). The landing page (feat(nav): analytics before execution; everyone lands on Prompts › Tracked Prompts #2475) makes this the first thing everyone waits for. On a fresh purchase the home URL carries
?jobId=, andTrackingJobHandoffthen callsreplaceStatewhile those actions are in flight. That's the Next 16 queue stall the page's own comments describe.feat(prompts): manage prompts in one place, on the Prompts page #2473 added a read for Track now (
_track-now.tsxuseTrackNow→lib/track-now.tsreadPromptsWithoutAnswers). It's a browser fetch to the API'sGET /api/tracking/unanalyzed/:brandIdon every manager's load whenever any active prompt had no answers in the window, which with the 24h default is almost always. That route reads theprompt_resultsrows of all active prompts (.in('prompt_id', 227 ids)) and PostgREST's 1,000-row cap cuts the list. So on a busy brand the count was also wrong, and the line appeared late in the status line.feat(prompts): show a tracked Improve action under the Work chip #2471 added one more server action per page of rows (
_improving-link.tsxuseImprovingPrompts→getImprovingPrompts). It fired after the rows, and again on every page, sort or filter that changed the rows on screen. When it landed, "AC-12 · Improving" appeared under the Work chip and made those rows taller.Problem 3: the volumes had no second chance, and their absence read as "not analyzed". The volumes came inside
getPromptsPageData(getPromptVolumes→ the API'sGET /api/volumes/brand/:id, with a 15 sAbortSignal.timeout). When that call failed or timed out, the action degraded tovolumes: [](volumesDegraded). Then:unanalyzedCountcounted every active prompt (227);loadData,tab === 'insights') showed "No volume data yet".Nothing read the volumes again until something reloaded the page data: a range change, or the volume-run watch reloading when a run finished, which is the "filled in by itself after a while". It is the first attempt failing, not just waiting. While the read is pending,
loadingis true and Insights shows its spinner and Tracked its skeleton. The empty state and the "227" need a finished read with no volumes. Waiting behind the queue (cause 1) made that read start late. Pages that loaded the volumes first (?rangeand the other tabs) also re-read them on every range change, although volumes have no date.getBrandFilterOptions(insights_filter_options) scans the brand's wholeprompt_resultshistory twice (DISTINCT region, DISTINCT model). It never blocked the table, but it was in the same queue. It's unchanged here; see the follow-ups.The home redirect (
/dashboard→readMyHome()→ redirect) adds no round trip on the critical path. Next renders the/dashboardpage segment alongside the dashboard layout: each segment's RSC has its own slot, seecreate-component-tree.readMyHome's three reads (authgetUser,profiles,organization_menu_rolesfor non-admins) are a subset of what the layout already reads in parallel. The hop itself existed before #2475, when it redirected to Action Center › Today. No change.What changed
The table's read is a fetch, not a server action:
POST /api/prompts/read(app/api/prompts/read/route.ts, client inlib/prompts-reads.ts). It follows the existing/api/visibility/readand/api/prompts/usagepattern: the member's session, RLS and the functions' brand checks, input validated with zod, and one log line per read with its duration.getPromptsPageDatabrings everything the first view shows in its onePromise.all. Each extra degrades on its own:readBrandImprovingActions: one query, scoped to the brand, the same rule);first, the column views (getPromptTableViews), so the table opens on its own columns;withoutAnswers(managers), the active prompts with no answers yet.readUnansweredPromptIds(lib/prompts-without-answers.ts) joins each active prompt to at most one of its answers (prompt_results(id)withlimit 1, by theprompt_idindex, scoped to the brand). That's one index probe per prompt, never the result rows, and there's no 1,000-row cap on the answer;volumes: falseleaves the volumes out (other callers keep them).The volumes are their own fetch, beside the rows (
POST /api/prompts/readvolumes). It returns the volumes and quota, plusgetVolumeAnalysisStatusfor "Analyzing…" on arrival, so that's no longer a server action either. The rows never wait for the volumes API. A failed read is tried once more at once. A range or location change doesn't read the volumes again. An older read landing after a newer one is dropped: there's a sequence guard on both reads, needed now that fetches run side by side.While the volumes are pending:
If both tries fail, Insights says "Volume data couldn't be loaded." with Retry, the existing warning toast shows, and the line stays hidden.
Track now takes its ids from the table's read. The
/unanalyzedfetch andreadPromptsWithoutAnswersare removed.Improve links come with the rows (
useImprovingPromptsgets them asseed).getImprovingPromptsnow runs only when the positions panel closes, for the rows on screen, so an Improve sent from the panel shows.getContentUsage(row menu and bulk bar quota) is read once the rows are in, not before them.The Location filter reads the brand's locations through
/api/visibility/read(filterOptions, as Visibility does), a fetch beside the table. While they're unread, a brand whose prompts track more than one location gets a placeholder of the filter's size, so the filter row doesn't shift.No migration, no new dependency, no new write action.
'use server'files still export async functions only. The new constants and helpers live in plain modules.Before / after: first view of Tracked Prompts (manager, brand with prompts lacking answers in 24h)
getPromptTableViews,getContentUsage,getTrackingWindow), thengetPromptsPageDataitself/api/volumes/brand, 15 s timeout)prompt_resultsrows (capped at 1,000)getBrandFilterOptions,getVolumeAnalysisStatus,getImprovingPrompts, andgetTrackingCountrieswhen a row shows "Within 24h"getTrackingWindow(shared first-run hook),getContentUsage, andgetTrackingCountrieswhen a row shows "Within 24h"Tests
page.test.tsx:readPromptsPageDatahas been called once (first,withoutAnswers,volumes: false) and no server action at all. Once it lands, the table opens on its own columns and still nogetImprovingPromptsorgetVolumeAnalysisStatushas run;Competition 42 of 100), "—" only for the prompt without a volume, the "not analyzed" count is the true one (1, not 3), and there's no range change;app/api/prompts/read/route.test.ts:nullturned intoundefined;improving-actions.test.ts: the brand-wide read is one query with no prompt list, and another brand's rows are ignored._improving-link.test.tsx: the seed is shown with no read; a re-read happens only after the panel closes, and merges for the rows on screen; a newer seed wins; a failed re-read keeps the seed.prompt.test.ts(getPromptsPageData): the Improve links come with the rows; the columns and Track now's prompts come only on request, in the same round;volumes: falsemakes no volumes API call; a failing extra leaves the rows intact.prompts-without-answers.test.ts: one query, the brand's active prompts,limit 1onprompt_results, norange; it lists the prompts whose probe found nothing.subscription-guard-coverage.test.tsnamesprompts/read:POSTas read-only, likevisibility/read.tsc --noEmitand ESLint on the changed files pass. Vitest passes 475 tests in 39 files: the Prompts page folder,src/app/api/prompts, the touchedsrc/lib/actionstests (prompt,prompt-positions),improving-actions,prompts-without-answers,track-now,src/components/prompts,src/lib/help,src/i18n,use-server-exportsandsubscription-guard(-coverage). Merged withfix/prompts-summary-lineandfix/prompt-suggestions-no-jump, in either order,tscand the Prompts, AI-usage, Help and guard tests pass too (384 tests).How to check in production
/dashboardwith DevTools › Network filtered toFetch/XHR. Before the table shows, there is onePOST /api/prompts/read(pageData) next tovolumes,/api/visibility/readand/api/prompts/usage. There's noPOST /dashboard/prompts/trackedwith aNext-Actionheader ahead of it, and noGET …/api/tracking/unanalyzed.[prompts/read] pageData NNNmsis the table's server time, and[prompts/read] volumes NNNmsthe volumes'. A… (slow)suffix marks one over 2 s./dashboard/prompts/insightsopens on a skeleton, then the cards, never "No volume data yet".[prompts] volumes fetch failed, rendering without them:. The message says which one:The operation was aborted due to timeout(the 15 s timeout),Server error: 429(the API's rate limiter), orNot authenticated/ 401.Follow-ups (not in this PR)
insights_filter_optionsscans the brand's wholeprompt_resultshistory twice. Check it withEXPLAIN (ANALYZE, BUFFERS) select * from insights_filter_options('<brand>'), or withpg_stat_statementsmean_exec_timefor it. A rollup (insights_brand_daily's regions) would make it cheap, but the Visibility pages read it too./dashboard/prompts/similar-topicsreadsgetPromptVolumeson its own and shows "No similar topics found." when that read fails: the same "a failure looks empty" pattern.Generated by Claude Code