Skip to content

fix: respect view.selectedItemId after lazy-loaded items hydrate (#55)#65

Merged
pablopunk merged 1 commit into
mainfrom
fractal-nvm-work-55-selecteditemid-race-lazy-loaded-items-focus-falls-80922f
Jun 21, 2026
Merged

fix: respect view.selectedItemId after lazy-loaded items hydrate (#55)#65
pablopunk merged 1 commit into
mainfrom
fractal-nvm-work-55-selecteditemid-race-lazy-loaded-items-focus-falls-80922f

Conversation

@pablopunk

Copy link
Copy Markdown
Owner

Problem

When a view uses ctx.data.loader() or ctx.data.staleWhileRevalidate() with a declared selectedItemId, the selection is evaluated against the current item set. If items haven't hydrated yet (empty array), selectedItemId resolves to empty string, and when items later arrive the first item (items[0]) gets focus instead of the intended one.

User-visible impact

Extensions that want to auto-focus a specific item (e.g., the current calendar event, the most recent screenshot) can't do it reliably with lazy-loaded data. The first item always gets focus on initial paint.

Root cause

selectionAfterPatch() in src/App.tsx — called when onViewHydrate or onViewPatch delivers items — checks:

  1. patch.selectedItemId (explicit patch override — not set during hydration)
  2. selectedValueRef.current (which is '' from the initial empty-items render)
  3. Falls to nextItems[0]?.idbug: never checks the view's declared selectedItemId

Fix

Added a check for next.selectedItemId (the view's declared intent) after patch-specific overrides but before falling back to current selection or index 0. This ensures the view's focus target survives the item hydration cycle.

Change

  • src/App.tsx: 5 lines added to selectionAfterPatch()

Acceptance

  • selectedItemId is respected after lazy-loaded items hydrate via ctx.data.loader()
  • selectedItemId is respected after stale-while-revalidate items hydrate
  • Pending focus target is cleared when view is replaced (no new state, existing lifecycle handles this)
  • Build and typecheck pass clean
  • All 68 backend tests pass

Closes #55

When a view uses ctx.data.loader() or ctx.data.staleWhileRevalidate()
with a declared selectedItemId, the selection is evaluated against the
current item set. If items haven't hydrated yet (empty array),
selectedItemId resolves to empty, and when items later arrive the first
item gets focus instead of the intended one.

Fix: selectionAfterPatch() now checks next.selectedItemId (the view's
declared intent) after patch-specific overrides but before falling back
to the current selection or index 0. This ensures the view's declared
focus target survives the item hydration cycle.
@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
nvm Ready Ready Preview, Comment Jun 21, 2026 5:57pm

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pablopunk, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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 credits.

🚦 How do rate limits work?

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

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7fc4895e-39c6-4bd6-a59a-67d30d3970fe

📥 Commits

Reviewing files that changed from the base of the PR and between a471f45 and e36f2b0.

📒 Files selected for processing (1)
  • src/App.tsx

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 and usage tips.

@pablopunk
pablopunk merged commit 52a6592 into main Jun 21, 2026
8 checks passed
@pablopunk
pablopunk deleted the fractal-nvm-work-55-selecteditemid-race-lazy-loaded-items-focus-falls-80922f branch June 21, 2026 18:07
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.

selectedItemId race with lazy-loaded items: focus falls to index 0

1 participant