Skip to content

perf(ui): prefetch mode homes for seamless switching - #1275

Merged
BigSimmo merged 22 commits into
mainfrom
codex/identify-and-fix-performance-issues-during-mode-switch
Jul 28, 2026
Merged

perf(ui): prefetch mode homes for seamless switching#1275
BigSimmo merged 22 commits into
mainfrom
codex/identify-and-fix-performance-issues-during-mode-switch

Conversation

@BigSimmo

@BigSimmoBigSimmo commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Mode switches could feel slow and visually janky because the mode menu uses imperative buttons (not Links), so Next.js could not automatically prefetch the destination RSC payloads; this left an avoidable latency path on menu-open → router.push.

Description

  • Add prefetchModeHomes() to src/components/clinical-dashboard/master-search-header.tsx which computes each distinct accessible mode-home href and calls router.prefetch(href) when the mode menu is opened or focused.
  • Import appModeHomeHref and wire prefetchModeHomes() from both the pointer/tap and keyboard menu-opening paths to warm RSC payloads without changing route ownership or optimistic chrome state.
  • Add a static regression contract in tests/audit-navigation-auth-regressions.test.ts that asserts the new prefetch helper and that it is invoked from both menu-opening callsites.
  • Record the focused performance review and verification evidence in docs/branch-review-ledger.md.

Testing

  • Ran npm run verify:cheap and its gates; result: PASS (25 gates).
  • Ran the focused unit/DOM tests used during development: node scripts/run-vitest.mjs run tests/audit-navigation-auth-regressions.test.ts tests/favourites-auth-gate.dom.test.tsx; result: PASS (20/20 focused assertions).
  • Ran the full unit suite (npm run test); result: PASS — 393 test files, 3,527 tests passed and 1 skipped.
  • Ran npx prettier --check and git diff --check; result: PASS.
  • Recorded check:branch-review-ledger run; result: PASS.
  • Browser E2E verification was attempted (targeted Playwright scenarios), but Playwright/browser execution could not complete because the Playwright Chromium binary was not available (CDN download returned HTTP 403), so the headful/Chromium E2E runs were blocked; the production build and TypeScript phases for those runs completed successfully.

Codex Task

Summary by CodeRabbit

  • Performance

    • Improved app mode navigation by preloading visible mode home pages when opening the mode menu, enabling faster transitions.
  • Tests

    • Added regression coverage to verify that mode home pages are prefetched correctly and consistently.

@supabase

supabaseBot commented Jul 27, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitaiBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@cursor[bot], you've reached your PR review limit, so we couldn't start this review.

Next review available in:58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bfdd3031-796d-4ac5-bc95-2b2fe4684c48

📥 Commits

Reviewing files that changed from the base of the PR and between 24605b5 and 9a9e416.

📒 Files selected for processing (4)
  • docs/branch-review-ledger.md
  • src/components/clinical-dashboard/master-search-header.tsx
  • tests/audit-navigation-auth-regressions.test.ts
  • tests/mode-menu-prefetch.dom.test.tsx
📝 Walkthrough

Walkthrough

Changes

Mode Prefetch and Review Ledger

Layer / File(s)Summary
Mode home prefetch behavior
src/components/clinical-dashboard/master-search-header.tsx, tests/audit-navigation-auth-regressions.test.ts
Visible app-mode home routes are derived and prefetched when either mode-menu opening path runs; a regression test checks the helper and both call sites.
Branch review ledger records
docs/branch-review-ledger.md
Review records are added or updated for PWA work, audit remediation, mode-switch follow-ups, babysit sweeps, fix-forwards, and protected-main reconciliation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers:cursoragent, copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title is concise and accurately describes the main change: prefetching mode-home routes to speed up switching.
Description check✅ PassedThe description covers motivation, implementation, and testing, but it does not follow the repository's template headings exactly.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/identify-and-fix-performance-issues-during-mode-switch

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.

@chatgpt-codex-connectorchatgpt-codex-connectorBot 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:24605b57e2

ℹ️ 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 threaddocs/branch-review-ledger.md Outdated

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/branch-review-ledger.md`:
- Around line 700-722: Fix the malformed rows in the branch-review ledger table,
especially the entry containing literal pipe characters that currently creates
eight cells instead of six. Escape any content pipes and normalize separator
usage so every affected ledger row has exactly six columns while preserving its
recorded text.
- Around line 685-723: Remove the duplicated dated ledger records in the
reviewed block, including entries whose SHAs already appear in the later
canonical block around the corresponding ledger records. Preserve the canonical
copies and maintain the append-only ledger’s unique record and SHA invariant so
check:branch-review-ledger continues to pass.
In `@tests/audit-navigation-auth-regressions.test.ts`:
- Around line 118-125: Replace the source-string count assertion in the
“prefetches mode homes when the mode menu opens” test with behavioral coverage:
mock router.prefetch, invoke both openModeMenuWithFocus and toggleModeMenu, and
verify each path prefetches the distinct hrefs generated from
visibleAppModeOptions via appModeHomeHref.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e0db041-8088-44be-8f2b-ee533d6ff838

📥 Commits

Reviewing files that changed from the base of the PR and between cdf7c04 and 24605b5.

📒 Files selected for processing (3)
  • docs/branch-review-ledger.md
  • src/components/clinical-dashboard/master-search-header.tsx
  • tests/audit-navigation-auth-regressions.test.ts

Comment threaddocs/branch-review-ledger.md Outdated
Comment threaddocs/branch-review-ledger.md Outdated
Comment threadtests/audit-navigation-auth-regressions.test.ts Outdated
@BigSimmo
BigSimmo enabled auto-merge (squash) July 27, 2026 21:45
@coderabbitai

coderabbitaiBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Cannot run autofix: This PR has merge conflicts.

Please resolve the conflicts with the base branch and try again.

Alternatively, use @coderabbitai resolve merge conflict to automatically resolve the conflicts.

@BigSimmo

Copy link
Copy Markdown
OwnerAuthor

@cursoragent resolve failing merge conflict

@cursor

cursorBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Merge conflict is resolved. PR #1275 is MERGEABLE again.

What was wrong: GitHub showed CONFLICTING/DIRTY, but git merge-tree was clean — staleness against main, plus a ledger rewrite that had mojibake’d ~95 historical rows.

What I did:

  • Merged origin/main into codex/identify-and-fix-performance-issues-during-mode-switch
  • Restored docs/branch-review-ledger.md byte-for-byte from main (append-only again)
  • Re-appended only the mode-switch review row + a sync closeout
  • Pushed tip 82c17f76

Product diff vs main is now just the prefetch change + regression test + 2 ledger appends. Focused navigation tests: 9/9 pass. Hosted required checks still need to finish (BLOCKED until CI is green).

Open in WebOpen in Cursor

cursoragentand others added 4 commits July 27, 2026 21:47
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Merge origin/main cleared the GitHub DIRTY/CONFLICTING stale state.
Restore branch-review-ledger historical records byte-for-byte from
main (undoing the mojibake rewrite), then append only the mode-switch
performance review and this sync closeout.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Tighten the source contract so leftover prefetchModeHomes strings cannot
satisfy coverage for openModeMenuWithFocus and toggleModeMenu.
@cursor

cursorBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Follow-up on tip 6c544c16: tightened the prefetch source contract so both openModeMenuWithFocus and toggleModeMenu must call prefetchModeHomes() before opening. Ledger restore + main sync were already on the prior tip.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitaiBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 3 unresolved review comments.

Files modified:

  • docs/branch-review-ledger.md

Commit:a5100d0507e6f7f64a8db3b585d7ea011503dd5a

The changes have been pushed to the codex/identify-and-fix-performance-issues-during-mode-switch branch.

Time taken:10m 42s

Fixed 1 file(s) based on 3 unresolved review comments.
Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@github-actions

Copy link
Copy Markdown
Contributor

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Production UIneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #5981 (success).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

BigSimmo added a commit that referenced this pull request Jul 27, 2026
* docs(ledger): record open-PR review and Bugbot sweep
Append review outcomes for the current open PR queue after #1277
merged, including merge-tree classification and pr-bugbot findings.
* docs(ledger): record open-PR recommendation implementation
Capture closeouts for the unsafe audit cluster and the follow-up fixes
pushed to #1273, #1275, #1280, and #1281.
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
cursoragentand others added 5 commits July 27, 2026 23:18
Restore branch-review-ledger byte-for-byte from origin/main and
re-append only this PR's review rows. The cited near-duplicate
PWA/credentialed/concurrency records already exist on main as
non-identical history; deleting them from a feature PR is not
allowed. Autofix a5100d0 had escaped content pipes and removed
historical rows.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Union merge interleaved history; restore origin/main as the
exact prefix and append only this PR's three review records.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursorBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit duplicate-ledger thread — dispositioned on tip 3952ec0b

Verified against current origin/main + this branch:

  • The cited near-duplicates (PWA-surface review, window, Credentialed release-gate checkpoint closeout, restarted; PR: ci.yml concurrency) already exist on origin/main (counts 2/2/2). They are not exact duplicates (check:branch-review-ledger PASS on main and on this tip).
  • Deleting one copy from this feature PR would rewrite main-owned append-only history — not allowed.
  • CodeRabbit autofix a5100d05 made things worse (escaped content | pipes and deleted historical rows). That rewrite is reverted.
  • Ledger is restored byte-for-byte from origin/main with only this PR’s three append rows. PR is MERGEABLE again; product diff remains prefetch + regression test + ledger appends only.

Malformed-row / pipe-escape comments: same disposition — those rows are main history; this PR no longer rewrites them.

cursoragentand others added 2 commits July 27, 2026 23:19
The MD056 cell-count warnings on ~700-722 match origin/main exactly.
This PR only appends ledger rows, so rewriting those historical pipes
is out of scope and would violate the append-only contract.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursorBot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit malformed-ledger-row thread — dispositioned on tip 0efcbdec

Verified against current code (per the agent prompt: fix only still-valid issues):

  • MD056 “Expected: 6; Actual: 5/8” on ~700–722 is identical on origin/main (same 16 BAD lines in that window; 41 non-6-column dated rows overall).
  • This PR’s ledger delta is append-only (origin/main is an exact byte prefix; +4 review rows at the end only).
  • Escaping historical content | here would rewrite append-only evidence — the same failure mode as autofix a5100d05 — and is out of scope for a mode-prefetch PR.
  • check:branch-review-ledger PASS. PR remains MERGEABLE.

If main wants markdown table hygiene for those historical rows, that should be a dedicated ledger cleanup change on main, not a rewrite inside #1275.

cursoragentand others added 3 commits July 27, 2026 23:21
Replace the source-string call-site count with a jsdom behavioral contract
that mocks router.prefetch and opens the mode menu via toggle click and
ArrowDown (openModeMenuWithFocus), asserting distinct appModeHomeHref values.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Append-only evidence that the menu-open prefetch contract is now behavioral.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Historical rows already match origin/main byte-for-byte; record the
resolved review evidence for the stale mojibake rewrite finding.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo
BigSimmo disabled auto-merge July 27, 2026 23:41
@BigSimmo

Copy link
Copy Markdown
OwnerAuthor

@cursoragent please resolve all CI failing tests after understanding the issue. Please also fix any comments and resolve them and also ensure that you fix with smallest required fix with best coding practice and u derstabding the fix rather than simple patch. Please fix any merge conflicts and ensure any issues are found. Please resolve any issues you find. Please also run bugbot. Please mark comments resolved also once you resolve them.

@cursor

cursorBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Resolved on tip 9a9e4168. PR #1275 is MERGEABLE again (required checks re-running).

What was actually wrong

  • Prior tip CI was already green; the blocker was a real merge conflict after main landed per-option prefetchModeHome (7ae4eb49) while this PR still bulk-prefetched every mode home.

Fix

  • Merged main and adopted its per-option prefetch (focus/pointer + dedupe).
  • Kept this PR’s value by warming only the highlighted option on menu open — not every mode.
  • Restored the ledger to an exact main prefix after union-merge duplicates, then re-appended only this PR’s rows.

Reviews / Bugbot

  • All review threads resolved (0 open).
  • Bugbot triage: no unresolved cursor[bot] defect findings on this head.

Checks

  • Focused vitest: 12/12 PASS
  • check:branch-review-ledger PASS
  • git merge-tree clean vs main
Open in WebOpen in Cursor

@BigSimmo
BigSimmo enabled auto-merge (squash) July 28, 2026 01:07
cursoragentand others added 4 commits July 28, 2026 01:09
Main landed focused/pointer prefetchModeHome. Resolve the audit-test
conflict by dropping bulk prefetchModeHomes, warming only the highlighted
option on menu open, and updating the DOM contract accordingly.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Append-only closeout for the conflict resolution against main's
per-option mode-home prefetch.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
GitHub reported CONFLICTING/DIRTY while git merge-tree was clean.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Union-merge of concurrent PR #1289 rows produced exact duplicates.
Restore docs/branch-review-ledger.md from origin/main and re-append
only this PR's disposition rows.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursorBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Sweep closeout (9a9e4168)

Root cause of “CI failing / merge conflict”

  • Required CI on prior tip 81005d18 was already green (PR required SUCCESS).
  • GitHub then showed CONFLICTING/DIRTY because main advanced with a real content conflict in tests/audit-navigation-auth-regressions.test.ts: main landed per-option prefetchModeHome (7ae4eb49), while this PR still had bulk prefetchModeHomes.

Fix (smallest correct design, not a patch)

  • Merged origin/main.
  • Adopted main’s per-option prefetch + dedupe ref.
  • Kept this PR’s intent by warming only the highlighted option on menu open (no bulk prefetch of every mode).
  • Updated static + DOM contracts accordingly.
  • Restored ledger to exact origin/main prefix after union-merge duplicates from concurrent Harden RAG retrieval and answer reliability #1289 rows; re-appended only this PR’s disposition rows.

Review threads

  • All 4 review threads resolved (0 unresolved), including CodeRabbit duplicate/malformed ledger dispositions (main-owned history).

Bugbot

  • Triaged per pr-bugbot: no unresolved cursor[bot] inline defect findings on the current head.

Verification

  • Focused vitest: mode-menu-prefetch.dom.test.tsx + audit-navigation-auth-regressions.test.ts12/12 PASS
  • check:branch-review-ledger PASS
  • git merge-tree origin/main HEAD clean
  • PR MERGEABLE (required checks re-running on this tip → BLOCKED until green)

@BigSimmo
BigSimmo merged commit 551f3f6 into mainJul 28, 2026
50 checks passed
@BigSimmo
BigSimmo deleted the codex/identify-and-fix-performance-issues-during-mode-switch branch July 28, 2026 01:22
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@BigSimmo@cursoragent