Skip to content

Fix prompt preview pane flickering#270

Merged
subsy merged 2 commits intomainfrom
fix-prompt-preview-flicker
Feb 4, 2026
Merged

Fix prompt preview pane flickering#270
subsy merged 2 commits intomainfrom
fix-prompt-preview-flicker

Conversation

@subsy
Copy link
Copy Markdown
Owner

@subsy subsy commented Feb 3, 2026

Summary

Fixes rapid flickering/redraw when viewing the prompt preview pane (Shift+O).

Root Cause

The useEffect that generates prompt previews depended on displayedTasks and iterations arrays:

useEffect(() => {
  const effectiveTaskId = displayedTasks[selectedIndex]?.id;
  setPromptPreview('Generating...');  // ← triggers re-render
  // ...
}, [displayedTasks, iterations, ...]);  // ← unstable array refs

If these arrays get new references (common in React), the effect fires repeatedly, calling setPromptPreview which triggers another render → infinite loop.

Fix

Extract the task ID into a memoized value, then depend on that stable string:

const promptPreviewTaskId = useMemo(() => 
  displayedTasks[selectedIndex]?.id,
  [displayedTasks, selectedIndex]
);

useEffect(() => {
  // ...
}, [promptPreviewTaskId, ...]);  // ← stable string, only changes on actual selection change

Test plan

  • Open prompt preview with Shift+O - no flickering
  • Switch between tasks - preview updates correctly
  • Switch between tasks/iterations views - preview updates correctly

Summary by CodeRabbit

Release Notes

  • Performance Improvements
    • Enhanced prompt preview feature stability with optimised refresh logic to minimise unnecessary re-renders and data fetches.

The useEffect for prompt preview depended on `displayedTasks` and
`iterations` arrays, which could have unstable references causing
the effect to fire repeatedly on every render.

Fix: Extract task ID computation into a memoized `promptPreviewTaskId`
value, then have the useEffect depend on that stable string instead
of the full arrays. This prevents the re-render loop since the string
only changes when the actual selection changes.
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 3, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ralph-tui Ignored Ignored Preview Feb 4, 2026 6:58pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

A refactoring of the RunApp component introduces a memoized promptPreviewTaskId derived from viewMode, iterations, and selected indices to replace effectiveTaskId usage in prompt preview logic, alongside a simplified dependency array for the related useEffect hook.

Changes

Cohort / File(s) Summary
Prompt Preview Logic Stabilisation
src/tui/components/RunApp.tsx
Introduces memoized promptPreviewTaskId to stabilise prompt preview task identifier. Replaces effectiveTaskId with promptPreviewTaskId in remote fetch and local engine calls. Simplifies useEffect dependency array by substituting granular task/iteration arrays with the single memoized identifier.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix prompt preview pane flickering' directly addresses the primary issue being resolved in the pull request—eliminating a re-render loop that caused visual flickering in the prompt preview component.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-prompt-preview-flicker

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.

@subsy subsy merged commit f06ce6f into main Feb 4, 2026
9 checks passed
@subsy subsy deleted the fix-prompt-preview-flicker branch February 4, 2026 19:08
sakaman pushed a commit to sakaman/ralph-tui that referenced this pull request Feb 15, 2026
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.

1 participant