Repository navigation
test(renderer): pin the runtime-target selector identity stability that #18685 fixed - #18625
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 62a9f29 and a3eb0e8036304caf2801b6b5f38e53557cc9931f. 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe hook now selects the execution host ID and memoizes the derived runtime target by that ID. A new test performs repeated unrelated Merge Risk: 🔵 Low · up to The runtime target change avoids rerenders from unrelated store updates, but the new test does not verify target identity when the hook itself rerenders. This is a bounded regression-coverage gap and should be addressed before relying on the test as protection for the memoization behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description includes useful context, testing details, and visual-proof justification, but it is incomplete and conflicts with the changeset. It states that the PR is test-only and contains no production code, while the summary shows production changes in use-worktree-runtime-target.ts. It also does not provide the required linked issue, Review section, Agent skill boundary checklist, Notes, or repository checklist. Resolution Update the description to accurately document both the production hook change and the regression test. Provide a valid linked issue or explain the required exception. Complete the Review, Agent skill upstream boundary, Notes, and Checklist sections, including the required validation commands and their results.
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 136d5dbb-0222-45b0-8a13-288b72467238
📒 Files selected for processing (2)
src/renderer/src/runtime/use-worktree-runtime-target-identity.test.tssrc/renderer/src/runtime/use-worktree-runtime-target.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| // A selector that built the target object inline re-rendered on every write. | ||
| expect(renders).toBe(rendersAfterMount) | ||
| expect(result.current).toBe(first) | ||
| }) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a direct rerender assertion for the memoization contract.
The current test only performs store writes. Because the selector now returns a primitive, those writes do not rerender the hook, so the identity assertion does not exercise useMemo. A regression that removes useMemo would still pass this test.
Trigger one explicit hook rerender and assert that result.current remains first before applying the store writes.
Proposed test adjustment
- const { result } = renderHook(() => {
+ const { result, rerender } = renderHook(() => {
renders += 1
return useWorktreeRuntimeTarget('worktree-1')
})
const first = result.current
const rendersAfterMount = renders
+ rerender()
+ expect(result.current).toBe(first)
+ const rendersAfterRerender = renders
+
act(() => {
for (let index = 0; index < 50; index += 1) {
useAppStore.setState({ activeRepoId: `repo-${index}` })
@@
- expect(renders).toBe(rendersAfterMount)
+ expect(renders).toBe(rendersAfterRerender)There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
use-worktree-runtime-target.ts— the selector now returns the primitiveExecutionHostIdstring and derives the target object viauseMemo([hostId]), stabilizing identity across unrelated store writes. This mirrors the existinguseAgentDetectionTargetForWorktreepattern.use-worktree-runtime-target-identity.test.ts— a new guard that renders the hook, drives 50 unrelatedactiveRepoIdwrites, and asserts both the render count and the returned target identity are unchanged.
The fix is correct: runtimeTargetForExecutionHostId is a pure function of hostId, and getExecutionHostIdForWorktree returns a plain string (compared by value under Zustand's Object.is), so selecting the string is referentially stable and useMemo cannot go stale. I confirmed the new test passes against the fixed hook and fails against the pre-change implementation (the old selector trips getSnapshot should be cached / "Maximum update depth exceeded" under happy-dom).
The useMemo is load-bearing, not redundant: PortsStatusSegment and the sidebar port rows pass runtimeTarget into useCallback deps, so keeping it identity-stable across parent re-renders (not just store writes) is what keeps those callbacks asleep. The lint rule no-fresh-selector-result correctly stays silent here because the selector returns a call expression, and extending it is reasonably left out of scope.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
a3eb0e8 to
ff98c61
Compare
…tablyai#18625) stablyai#18685 landed the fix (select the host id, derive in useMemo) without a regression guard. This is that guard: it drives 50 unrelated store writes and asserts the consumer re-renders once and the returned target keeps its identity. Confirmed to fail against the pre-stablyai#18685 hook (51 renders).

ELI5
A hook that tells the ports UI which machine owns a workspace was building its answer object fresh inside the store subscription. React compares by identity, so a brand-new object always looks "changed" — and the always-mounted status-bar Ports segment re-rendered on every single write to the app store.
That fix has since landed on
mainvia #18685. It landed without a test. This PR is that test.What Changed
Test only.
src/renderer/src/runtime/use-worktree-runtime-target.test.tsrenders the hook, drives 50 unrelated store writes, and asserts two things: the consumer renders exactly once, and the returned target keeps its referential identity.No production code —
mainalready has the fix.Why
I found and fixed this independently while auditing renderer render-churn; #18685 shipped the same change first (
useAppStore(state => getExecutionHostIdForWorktree(...))thenuseMemo), so I dropped my duplicate implementation and rebased this branch down to the regression guard.Worth keeping, because the bug is invisible without one: the hook returns a structurally correct value either way. Only the identity differs, so nothing fails, nothing looks wrong, and the cost shows up as unexplained baseline render churn that scales with store traffic. A future refactor could reintroduce it silently. This test fails loudly instead — verified at 51 renders vs 1 against the pre-#18685 hook.
Measurements
Negative user-facing trade-offs
None — this PR contains no production code. It adds one test file.
Merge risk
Very low. Test-only, on the current
main, covering a fix that is already merged. The worst case is a flaky test, and it is not timing-based: it counts renders and compares object identity.Linked Issue
No tracked issue — found by a repository-wide performance audit. Related: #18685.
Visual Proof
N/A — no production change.
Testing
pnpm test src/renderer/src/runtime/use-worktree-runtime-target.test.tspasses on currentmain, and was confirmed to fail against the pre-#18685 hook.Platforms: renderer-only, no platform-dependent behavior.
AI Disclosure