Skip to content

⚡ Bolt: Optimize session drawer polling and re-renders - #70

Open
parvezk wants to merge 1 commit into
mainfrom
bolt-session-drawer-optimization-4884745908084273745
Open

⚡ Bolt: Optimize session drawer polling and re-renders#70
parvezk wants to merge 1 commit into
mainfrom
bolt-session-drawer-optimization-4884745908084273745

Conversation

@parvezk

@parvezk parvezk commented Jul 27, 2026

Copy link
Copy Markdown
Owner

💡 What

  • Replaced a useEffect synchronization pattern with a "derived state during render" pattern for session.id.
  • Added dynamic disabling of SWR's refreshInterval polling (setting to 0) when a session reaches a terminal state (completed or failed).

🎯 Why

  • Using useEffect to synchronize internal component state with props causes an unnecessary double-render cycle, hurting frontend performance.
  • Polling via SWR on a session that has already finished resulted in unnecessary continuous network requests to /api/sessions/[id] and wasted backend database reads.

📊 Impact

  • Renders: Eliminates one unnecessary React commit/paint layout cycle per session switch.
  • Network: Saves 1 HTTP request and 1 database read every 4 seconds per actively-viewed completed session.

🔬 Measurement

  • Test by opening a completed session in the drawer and observing the network tab in browser devtools: there will be no continuous fetch requests every 4 seconds.
  • Verify tests via pnpm test and formatting via pnpm lint.

PR created automatically by Jules for task 4884745908084273745 started by @parvezk

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cursor

cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
polyagent Ready Ready Preview, Comment Jul 27, 2026 8:35am

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 85527e8884

ℹ️ 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".

// Optimization: Disable polling when the session is in a terminal state (completed or failed).
// Impact: Saves 1 network request and database read every 4 seconds for completed sessions.
const { data } = useSWR<DetailResponse>(session ? `/api/sessions/${session.id}` : null, fetcher, {
refreshInterval: session?.status === "completed" || session?.status === "failed" ? 0 : 4000,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop polling from the live detail status

When the drawer is opened while a session is running, session remains the snapshot stored by DashboardPage; subsequent /api/sessions refreshes update SessionTable but never update that selected object. Therefore, even after the detail response reports data.session.status as completed or failed, this expression continues returning 4000 and polls indefinitely. Derive the interval from the latest detail data, such as with SWR's functional refreshInterval, so sessions that finish while the drawer is open actually stop polling.

Useful? React with 👍 / 👎.

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