Skip to content

perf(web): load home before the rest of the app shell - #2289

Merged
Quick104 merged 11 commits into
mainfrom
perf/web-home-first-load
Oct 11, 2026
Merged

Quick104 merged 11 commits into
mainfrom
perf/web-home-first-load

Conversation

@Quick104

@Quick104 Quick104 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1142 C1 (Home loads the same rows sooner; not yet run)

On the web, Home's first row waits behind four requests in a row: token refresh, the account read, the layout, then the row's items. The layout itself waits until the account read finishes, and on a plain-HTTP server it also queues behind about fifteen startup requests from the app shell, because the browser opens at most six connections per server. On a 40 ms connection the first row appeared about 1.1 s after navigation. This change starts Home's requests earlier and sends fewer of them.

Uses include_items on GET /api/v2/home/layout, added in #2287.

Approach

  • Start Home with the session. On / with a stored profile, the layout request starts right after the token refresh, beside the account read. Its request and token only need what the refresh already restored.
  • First rows with the layout. The layout query asks for include_items=3 and writes each included row into that row's item cache before the layout resolves, so Home treats those rows as loaded and doesn't request them again. Later rows load as before. If the server rejects include_items with 422 (an older node during a rolling upgrade), the layout is read again without it and Home loads every row itself.
  • Batched settings reads. Single-key effective-settings reads (useSettingValue) started in the same tick for the same scope share one request; each query keeps its own cache entry and gets only its keys. If a shared request fails because of an unknown key (422 with a query.keys error), each query re-reads its own keys so only the one that asked for the unknown key fails.
  • Background widgets wait. The admin activity indicator and the unread-notification badge start once Home has its first rows, or after 1.5 s. Other pages release them on mount. Sidebar items that decide which links appear are not delayed.

Validation

  • tsc -b, pnpm run lint (0 errors), pnpm run format:check, pnpm run build, pnpm run budget:check: pass.
  • make test-web: 849 of 850 files pass; the one failure (GlobalSearch.test.tsx) happened while two suites ran on the same machine and passes on three reruns of that file. The signed-in boot test now asserts that the layout starts beside the account read and that boot sends 14 requests instead of 18.
  • New tests cover settings batching (shared request, failure, unknown-key isolation using the server's 422 fixture), cache seeding from included rows (including their one-hour cache lifetime), the 422 fallback for include_items, and the startup gate.

Evidence

Headless Chromium against a test server over plain HTTP, fresh tab, logged in, 40 ms emulated round trip, rows of 40, medians of 5 runs. Measured with the companion rendering PR (#2288) applied:

Before After
First row in the DOM 1,121 ms 375 ms
First row image loaded 1,302 ms 499 ms
LCP 1,288 ms 532 ms
API requests during load 42 31

Nothing changes visually; rows and badges appear sooner. Surface and build: web app, desktop.

Risks

  • A prefetch for a stored profile whose PIN session expired gets the same 403 Home would get; Home refetches on mount.
  • The startup gate stays released for the life of the tab, including after a profile switch.
  • Batched settings reads ignore the abort signal, as single reads did before.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (Claude Agent SDK), running in T3 Code
  • Tool(s): Claude Code, including Claude Code subagents
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, at a maintainer's direction; maintainer review pending
  • Adversarial review: a separate Claude Code subagent reviewed settings batching (profile switch, cancellation, invalidation, error isolation), the startup gate, the prefetch (PIN-protected or stale profiles, logout races), and cache seeding. It found and fixed one bug before this PR: one unknown key failed every batched read; the remaining notes are under Risks.

🤖 Generated with Claude Code

Quick104 and others added 2 commits October 11, 2026 15:04
GET /api/v2/home/layout takes optional include_items (0-4) and image_size.
The response (new HomeLayout schema) carries included_sections: the first
rows' items, built by the same code as GET /api/v2/home/sections/{id}/items.
Rows not ready within 300 ms, or whose fetch fails, are left out for the
client to fetch on its own. Without include_items the endpoint costs what it
did before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Home's layout request starts as soon as the session token is refreshed,
beside the account read, and asks for the first three rows' items so they
paint without a second round trip. Single-key effective-settings reads
started in the same tick share one request. The admin activity indicator and
the unread-notification badge wait until Home's first rows load (at most
1.5 s), so their requests no longer queue ahead of Home's on HTTP/1.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T23:00:26.946411Z 3423b66 New commits
🔒 Security Review ✅ Completed 2026-10-11T23:01:27.168673Z 3423b66 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72677347-faee-43d1-90c6-02186fb72dbc

📥 Commits

Reviewing files that changed from the base of the PR and between fee2f04 and 3423b66.


📒 Files selected for processing (11)
  • web/src/components/AppSidebar.tsx
  • web/src/components/Layout.tsx
  • web/src/hooks/queries/sections.test.ts
  • web/src/hooks/queries/sections.ts
  • web/src/hooks/queries/settingValues.test.tsx
  • web/src/hooks/queries/settingValues.ts
  • web/src/hooks/useAuth.tsx
  • web/src/lib/startupPriority.test.ts
  • web/src/lib/startupPriority.ts
  • web/src/pages/Home.tsx
  • web/src/test/signedInBoot.test.tsx

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes impact: polish Annoyance, cosmetic, or nice-to-have javascript Pull requests that update javascript code priority: P2 Limited scope, workaround exists, or polish stacked Base is another open PR; merge in stack order named in the body labels Oct 11, 2026
@silo-triage

silo-triage Bot commented Oct 11, 2026

Copy link
Copy Markdown

Rows and badges now appear at different times, even if the loaded page looks unchanged. Please add a before/after startup recording showing Home rows and the delayed badges at desktop and phone widths (or show mobile is unaffected), using the same data and naming the builds. The timing table includes #2288; keep that distinction clear in the captures too.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38bfb2fef3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +98 to +101
for (const section of layout.included_sections) {
queryClient.setQueryData<HomeSectionItemsResponse>(sectionKeys.homeItems(section.id), {
section: sectionFromV2(section),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate included-row updates to the mounted Home page

When the layout refetches while Home is already mounted—for example, after its 10-minute stale time elapses and the window regains focus—these calls refresh the row caches, but Home renders from its separate loadedSections state. That state is only rebuilt when the layout structure or refresh signal changes, so an unchanged layout leaves the first three rows showing their old items even though their caches have just been marked fresh; completedIds also prevents the row loader from fetching them again. Update the mounted Home state when included rows arrive, or make Home observe those cache entries.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visible behavior doesn't change here. Before this PR, a background layout refetch didn't update a mounted Home's rows either: Home rebuilds loadedSections only when the layout's cacheResetKey or section list changes, and completedIds keeps rows it already has. This PR only adds fresher entries to the row caches. Wherever Home marks a row complete from cache freshness (the reset effect), it reads that row's items from the same cache, so it can't skip a fetch and keep showing older items. A real refresh still invalidates the rows first (invalidateMediaSurfaceQueries), so it goes to the network.

Comment thread web/src/hooks/queries/sections.ts Resolved
Quick104 and others added 3 commits October 11, 2026 17:28
setQueryData created the seeded row entries with the client's default
10-minute gcTime, and Home never refetches a fresh row to raise it, so
the first rows were evicted before the later ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The 300 ms budget for included rows now covers each row's card lookups
  (user states, overlays, playable targets, artwork), not just its fetch,
  so a slow lookup leaves the row out instead of delaying the layout.
- A caller waiting on a shared resolved-list rebuild stops waiting when
  its context ends; the rebuild keeps running detached and fills the
  cache. A panic in a detached build becomes an error.
- Add GET /api/v2/home/capabilities (getHomeCapabilities) with
  include_items_max, so a client sends include_items only to a server
  that accepts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fe7f822c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/hooks/queries/sections.ts Resolved
Comment thread web/src/hooks/queries/settingValues.ts Resolved
Quick104 and others added 5 commits October 11, 2026 17:43
…g key

- A server that predates include_items (an older node during a rolling
  upgrade) or allows fewer rows answers 422; Home then reads the layout
  alone and loads every row itself.
- An unknown setting key fails the whole effective-settings read with 422
  and a query.keys error, not 404, so the per-caller retry never ran and
  one unknown key failed every batched read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from feat/home-layout-included-rows to main October 11, 2026 22:55
@silo-kody

silo-kody Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 7db3178 into main Oct 11, 2026
20 of 31 checks passed
@Quick104
Quick104 deleted the perf/web-home-first-load branch October 11, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes impact: polish Annoyance, cosmetic, or nice-to-have javascript Pull requests that update javascript code priority: P2 Limited scope, workaround exists, or polish stacked Base is another open PR; merge in stack order named in the body

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant