Skip to content

⚡ Bolt: Optimize TopNavbar telemetry rendering#18

Open
Jandave0 wants to merge 1 commit into
P2/3--Refactor-&-Reliabilityfrom
bolt/topnavbar-telemetry-optimization-8773569652792296493
Open

⚡ Bolt: Optimize TopNavbar telemetry rendering#18
Jandave0 wants to merge 1 commit into
P2/3--Refactor-&-Reliabilityfrom
bolt/topnavbar-telemetry-optimization-8773569652792296493

Conversation

@Jandave0
Copy link
Copy Markdown
Owner

@Jandave0 Jandave0 commented May 21, 2026

💡 What: Swapped useTelemetry() context consumption in TopNavbar for a direct subscription to telemetryBus.status using useSyncExternalStore.
🎯 Why: useTelemetry() updates every 2 seconds as new telemetry data (watts, wind speed, etc.) arrives. This caused the entire TopNavbar—including the computationally heavy Clerk UserButton—to unnecessarily re-render on every tick, even though the navbar only cares about the MQTT connection status which rarely changes.
📊 Impact: Eliminates ~30 unnecessary re-renders per minute in the TopNavbar, reducing main thread blocking and CPU usage.
🔬 Measurement: Use React DevTools Profiler. Prior to the change, TopNavbar will flash green every 2 seconds. After the change, it will only flash when the MQTT status changes from connecting to connected/disconnected.


PR created automatically by Jules for task 8773569652792296493 started by @Jandave0

Summary by CodeRabbit

Release Notes

  • Performance Improvements
    • Optimized MQTT connection status display in the top navigation to handle high-frequency telemetry data updates more efficiently, reducing UI lag.

Review Change Stack

- Used `useSyncExternalStore` directly on `telemetryBus.onStatus` instead of subscribing to the entire `useTelemetry` context.
- This prevents `TopNavbar` (and the heavy `UserButton` inside it) from re-rendering every 2 seconds when high-frequency telemetry data (watts, etc.) updates.
- Added a `.jules/bolt.md` entry to document the learning about React Context with fast-updating feeds.

Co-authored-by: Jandave0 <185737041+Jandave0@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: df26461a-216a-4ce1-8fd1-f57c5158ab05

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt/topnavbar-telemetry-optimization-8773569652792296493

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/layout/top-navbar.tsx`:
- Around line 44-51: The component currently ignores the mqttConnected prop by
reading status directly from telemetryBus via useSyncExternalStore
(telemetryBus, useSyncExternalStore, status), which silently breaks the public
contract; either remove the mqttConnected prop/JSDoc from the TopNavbar
component and related typings/usages, or make mqttConnected an explicit
fallback/override by using it when telemetryBus.status is undefined/unavailable
(e.g., compute status = telemetryBus.status ?? (mqttConnected ? "connected" :
"disconnected")), and update the component prop docs to reflect the chosen
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0fcca770-0a29-4db2-9f5a-1e5ba7a0588b

📥 Commits

Reviewing files that changed from the base of the PR and between ac6d2f2 and df2d238.

📒 Files selected for processing (2)
  • .jules/bolt.md
  • components/layout/top-navbar.tsx

Comment on lines +44 to +51

// Use useSyncExternalStore directly on the telemetryBus to avoid re-rendering
// every 2 seconds when telemetry data (watts, etc.) updates.
const status = useSyncExternalStore(
useCallback((cb) => telemetryBus.onStatus(cb), []),
() => telemetryBus.status,
() => "disconnected" as const
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove or honor mqttConnected; it is ignored now.

This subscription bypasses the mqttConnected prop entirely, so callers can still pass a public prop that no longer affects the rendered status. Either delete the prop/JSDoc or make it an explicit fallback/override to avoid a silent contract break.

Suggested cleanup if the bus is now the sole source of truth
 export interface TopNavbarProps {
-  mqttConnected?: boolean;
 }
@@
- * `@param` mqttConnected - Whether the MQTT connection is active (default: `false`).
  * `@returns` The header element containing navigation controls and status/profile indicators.
  */
-export function TopNavbar({ mqttConnected = false }: TopNavbarProps) {
+export function TopNavbar({}: TopNavbarProps) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/layout/top-navbar.tsx` around lines 44 - 51, The component
currently ignores the mqttConnected prop by reading status directly from
telemetryBus via useSyncExternalStore (telemetryBus, useSyncExternalStore,
status), which silently breaks the public contract; either remove the
mqttConnected prop/JSDoc from the TopNavbar component and related
typings/usages, or make mqttConnected an explicit fallback/override by using it
when telemetryBus.status is undefined/unavailable (e.g., compute status =
telemetryBus.status ?? (mqttConnected ? "connected" : "disconnected")), and
update the component prop docs to reflect the chosen behavior.

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