Skip to content

perf(dashboard): Embed core data in the dashboard page - #2724

Merged
thomasjiangcy merged 1 commit into
mainfrom
perf/dashboard-bootstrap-core-data
Nov 5, 2026
Merged

thomasjiangcy merged 1 commit into
mainfrom
perf/dashboard-bootstrap-core-data

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

The dashboard reads /api/me and /api/config only after the HTML and JS load, and personal spend and the review count wait for that read. In one Jaipur pageload (trace a435579560c24b90a031b8da84156cf9), /api/me started about 1.4s after the HTML arrived. It took 264ms in the browser and 31ms on the server. Network overhead per request is p50 ~275–300ms from APAC (SG 299ms, IN 273ms) and ~110–170ms from EU (AT 171ms, GB 123ms, ES 113ms). So removing that round trip matters most for users far from the region.

Now the page route builds the same identity and config payloads that the API returns and embeds them in the shell as window.__JUNIOR_DASHBOARD_BOOTSTRAP__ (escaped with scriptJson). The /api/me and /api/config handlers and the page share one builder each, so the two outputs cannot drift. The client takes the embedded data once, validates it, and uses it as React Query initialData for ["dashboard", "core"]. Spend and review count then start on the first render. Refetches, invalidations, and the setQueryData calls after PATCH /api/me still go through the API and cache as before. If the viewer read fails, the page renders without the embedded data and the client falls back to its current API read. The HTML never fails because of this. The HTML stays no-store.

Trade-off: the page response does the viewer, avatar, and auto-archive reads, which adds about 24–47ms of server time to the HTML. In exchange, the client skips one round trip.

Not verified: real pageload timing after deploy. The full dashboard e2e run had one failure in conversations-mobile.spec.ts:615 (toBeInViewport). That test passed 5/5 when run alone, so it looks like a timing flake, but I did not compare it against a full run on main.

This is separate from the asset-route work in the other PR. It touches shell.ts/app.ts only on the page data path, so any conflict should be textual.

via @thomasjiangcy.

--

View Session [Sentry]

The page shell now carries the /api/me and /api/config payloads, so the
client renders signed-in UI and starts gated queries without a first API
round trip. If the viewer read fails, the page renders without the data
and the client reads the API as before.

Co-Authored-By: Thomas Jiang <[email protected]>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 5, 2026 8:55am UTC

Request Review

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

6 screenshot changes — 6 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed
System Cache Share · Desktop
System Cache Share · Desktop
Changed
System Cache Tokens · Desktop
System Cache Tokens · Desktop
Changed

@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 5, 2026 09:00
@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 5, 2026
@thomasjiangcy
thomasjiangcy merged commit 013da82 into main Nov 5, 2026
44 checks passed
@thomasjiangcy
thomasjiangcy deleted the perf/dashboard-bootstrap-core-data branch November 5, 2026 09:25
BYK added a commit that referenced this pull request Nov 5, 2026
…#2764)

On a cold load of `/conversations/:id`, the first detail read started
only after the entry module downloaded and ran. In prod (0.280.0) that
was 650–1,100ms after navigation start. An inline head script now starts
that read while the browser downloads the client, and the client uses
its response.

## How it works

- `conversationOpenScript(basePath)` (new `src/conversation-open.ts`)
runs in the shell `<head>`, only on `/conversations/<id>` (and not
`new`), with the base path removed, using the same match as
`conversationIdFromPath`. It builds the exact path of the client's first
read: `/api/conversations/<id>?unreadPage=true&mailbox=true`, or
`?mailbox=true` when the start position is `latest`. It reads the same
localStorage key, which now lives in `conversation-open.ts` so the
script and `transcriptReadPosition.ts` share it.
- `readDashboardResponse` takes that response once, and only for the
same path and only when it sends no validator. Every other read,
including polls that send the detail version, fetches as before. If the
path drifts, the result is one extra read, never wrong data. 401
handling, error handling, and `recordDashboardServerVersion` run on the
early response too.
- **ETag/304:** the first read has no cached copy, so it sends no
validator and can't get a 304. The response still carries the detail
version header, so later polls revalidate as before.
- **Auth:** it's a same-origin GET with `credentials: "same-origin"`,
the same as the client read. The shell is served only to authenticated
viewers.
- **CSP:** the dashboard shell sends no CSP header and already has
inline scripts (theme, Sentry config, error handler), so no nonce is
needed.
- **Tracing:** the script copies the `sentry-trace` and `baggage` meta
values onto the request, so the server span stays in the page request's
trace.
- **Placement:** the script goes after the Sentry meta tags and before
the stylesheet link, because an inline script after a stylesheet waits
for the CSS. This PR also moves `renderSentryHead` above the stylesheet
for that reason.
- A rejected early fetch gets a no-op `catch`, so it can't trigger the
page's `unhandledrejection` error screen before the client takes it. The
client still sees the rejection.

I chose this over embedding the detail in the HTML (like #2724) because
embedding would hold the HTML response for the detail read, which is p50
216ms for 200s in prod. It would also need its own ETag and mailbox
handling on the server.

## Timing (Playwright, mock conversations, cold cache, median of 7)

Measured on main at `a2ba54556` (with #2757 static assets) before and
after this change. Conversation `internal:dashboard-qa`. Times are ms
from navigation start. "Transcript shown" is the first
`[data-transcript-seq]` row in the DOM.

| Profile | Detail request starts | Transcript shown |
|---|---|---|
| 40ms RTT, 50 Mbps, no CPU throttle | 973 → **66** | 1,383 → **1,211**
(−172) |
| 150ms RTT, 12 Mbps, 4× CPU throttle | 3,770 → **238** | 5,120 →
**4,885** (−235) |

Every run made exactly one detail request. The detail read now finishes
about 600ms before the transcript renders, while it competes with the JS
downloads for bandwidth. The rest of the cold-open path is client boot.

## Tests

- I extended `opens where the reader left off and reports what they
read` (`e2e/conversations-read-position.spec.ts`). It holds all client
JS and checks that the detail read still arrives. It then checks that
the open makes no second read, for both the `unread` and the `latest`
start positions. This catches a URL drift between the script and
`readConversationData`.
- I also checked route matching by hand: root and `/ops` base paths, an
encoded `local:web:` id, `/conversations/new`, nested paths, and a
base-path prefix mismatch.

## Checks

- `pnpm test:e2e:dashboard`: 100/100 passed.
- Dashboard `typecheck` and `lint` pass. lint-staged passed:
file-length, test-architecture and dashboard-style.
- Dashboard unit tests: 370 passed, 1 failed. The failure is
`dashboard-output.test.ts`, which also fails on clean main in my sandbox
(`MISSING_EXPORT nitroIntegration` from a hoisted
`@sentry/[email protected]`).

## Notes

- I rebased this onto main after #2757 (`perf/dashboard-static-css`)
merged, and resolved the conflict in the shell `<head>`. Inline Tailwind
is gone and the script sits before the new stylesheet link.
- Hover prefetch (#2723) and the open refetch work as before. A
client-side navigation never takes the early response, because the shell
only sets it on a full page load.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Adcae193f23dc8c1589b3fb8e4e36e0c1 -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/agent%3Adcae193f23dc8c1589b3fb8e4e36e0c1/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — efe1a6ec Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant