fix(trees): persist FileTreeView initial-snapshot flag across re-subscribes#918
Merged
Merged
Conversation
…cribes The controller-subscription effect re-subscribes whenever its layout/viewport deps change. The "have we seen the initial snapshot yet?" guard lived in an effect-local `let`, so it reset to false on every re-subscribe and swallowed the render-revision bump on the first real emit after each re-subscribe — the model updated but the rendered rows went stale until the next emit. Hoist the flag to a component-instance `useRef` so the initial-render optimization is preserved while every re-subscribe still repaints on its first real emit. The bump decision is extracted into a pure, unit-testable helper (shouldBumpControllerRevision) following the existing rowClickPlan/focusHelpers convention. Fixes #883 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FDXG4jRZT8sPS1YBSes2pR
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
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.
Requested by Alex · Slack thread
Description
FileTreeView's controller-subscription effect re-subscribes whenever its layout/viewport deps change (controller,initialViewportHeight,itemHeight,overscan,stickyFolders). The guard that suppresses the redundant re-render on the genuine initial snapshot lived in an effect-locallet hasSeenInitialControllerSnapshot = false;, so it reset tofalseon every re-subscribe — not just on mount.This change hoists the flag to a component-instance
useRefso the suppression happens only once per component instance, and extracts the bump decision into a small pure helper,shouldBumpControllerRevision, following the existingrowClickPlan/focusHelpersconvention.Before: A host that keeps the tree mounted and applies live controller mutations could intermittently drop a mutation — whenever a real mutation landed as the first emit after a re-subscribe, the model updated (and the imperative
update()ran) but the render revision was never bumped, so the rendered rows stayed stale until the next emit.After: Every re-subscribe still skips only the genuine initial snapshot; the first real emit after any re-subscribe bumps the revision and repaints. Hosts that fully remount on each change were never affected (the remount masked it), so no behavior change for them.
Motivation & Context
Fixes the stale-DOM-after-re-subscribe bug reported in #883, where the model was correct but the rendered rows lagged a mutation behind for mounted, live-updating trees.
How
packages/trees/src/render/FileTreeView.tsx: replace the effect-localletwith a component-levelhasSeenInitialControllerSnapshotRef = useRef(false), and drive the subscribe callback through the new helper.packages/trees/src/render/controllerSnapshotSubscription.ts(new): pureshouldBumpControllerRevision(holder)— suppresses only the first emit observed by a given persistent holder, bumps every emit after that.Type of changes
Tests
Added
packages/trees/test/controller-snapshot-subscription.test.ts(bun:test) covering the re-subscribe-then-first-emit path:letwas wrong.Full
packages/treessuite passes locally (307 tests).oxlint,oxfmt --check, andtsgo --noEmitare clean on the changed files.Checklist
oxfmt --check,oxlint)packages/treesbun:test)How was AI used in generating this PR
Authored with Claude Code (Claude Opus 4.8): diagnosis, the
useReffix, the extracted pure helper, and the regression tests. A human should review before merge.Related issues
Fixes #883
Generated by Claude Code