Skip to content

Coalesce component renders during Blazor WebAssembly startup #12753#12754

Draft
yasmoradi wants to merge 1 commit into
bitfoundation:developfrom
yasmoradi:perf/12753-coalesce-wasm-startup-renders
Draft

Coalesce component renders during Blazor WebAssembly startup #12753#12754
yasmoradi wants to merge 1 commit into
bitfoundation:developfrom
yasmoradi:perf/12753-coalesce-wasm-startup-renders

Conversation

@yasmoradi

@yasmoradi yasmoradi commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Adds an opt-in render-coalescing mechanism to AppComponentBase that collapses a burst of StateHasChanged calls during the app startup window into a single trailing render. It is active only on Blazor WebAssembly (where startup rendering is the bottleneck) and disabled by default.

Changes

  • New AppComponentBase.Rendering.cs: overrides ShouldRender to debounce renders during the startup window. Suppressed renders (re)arm a single trailing render so the final startup state is guaranteed to paint. Tunable via CoalesceRendersDuration (default 3s, measured from app start) and CoalesceRendersWindow (default 300ms quiet period). Only runs when AppPlatform.IsBrowser; everything else renders normally.
  • AppComponentBase.cs: adds a DisposeRenderCoalescing() partial invoked from DisposeAsync so the coalescing timer is always released; the whole feature stays isolated in its own file and compiles away when absent.
  • Opt in (CoalesceRenders => true) for AppShell, Header, NavBar, HomePage, and AppAiChatPanel.

Related Issue

This closes #12753

Summary by CodeRabbit

  • Performance Improvements
    • Improved startup responsiveness by combining rapid, repeated UI updates into fewer renders.
    • Enabled smoother initial rendering across the application shell, navigation, header, home page, and AI chat panel.
    • Added safe cleanup of rendering resources when components are disposed.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d2a902ac-40d0-497a-856d-d4d53782f1e7

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:

  • 🔍 Trigger review

Walkthrough

Changes

Startup render coalescing

Layer / File(s) Summary
Render coalescing control
src/Templates/Boilerplate/.../Components/AppComponentBase.Rendering.cs
Adds configurable startup timing and debounces opt-in WebAssembly renders, allowing one trailing render through InvokeAsync.
Render timer disposal
src/Templates/Boilerplate/.../Components/AppComponentBase.cs, src/Templates/Boilerplate/.../Components/AppComponentBase.Rendering.cs
Disposes the coalescing timer and prevents further coalesced renders during component disposal.
Component opt-ins
src/Templates/Boilerplate/.../Components/Layout/*, src/Templates/Boilerplate/.../Components/Pages/Home/HomePage.razor.cs
Enables render coalescing for the shell, header, navigation bar, AI chat panel, and home page.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Component
  participant AppComponentBase
  participant ITimer
  participant Renderer
  Component->>AppComponentBase: Trigger StateHasChanged
  AppComponentBase->>AppComponentBase: Suppress intermediate render
  AppComponentBase->>ITimer: Schedule trailing render
  ITimer->>Renderer: InvokeAsync(StateHasChanged)
  Renderer->>AppComponentBase: Execute trailing render
Loading

Poem

A bunny saw renders hop in a stream,
So bundled their beats like a startup dream.
One timer went “tick,”
The last frame came quick,
Then cleanup tucked it away neat and serene.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: startup render coalescing for Blazor WebAssembly components.
Linked Issues check ✅ Passed The changes add startup render coalescing and enable it for AppShell, Header, NavBar, HomePage, and AppAiChatPanel as requested.
Out of Scope Changes check ✅ Passed All edits are directly related to the startup render-coalescing feature and its target components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai 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.

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
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.Rendering.cs`:
- Line 26: Initialize the passCoalescedRender field in
AppComponentBase.Rendering to false instead of true, preserving the existing
timer-based coalescing behavior after Blazor’s unconditional initial render.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 97423195-5e6b-4249-9e6a-804a7577881f

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc0aea and f780f84.

📒 Files selected for processing (7)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.Rendering.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppAiChatPanel.razor.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppShell.razor.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/Header/Header.razor.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/NavBar.razor.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Home/HomePage.razor.cs

@yasmoradi
yasmoradi force-pushed the perf/12753-coalesce-wasm-startup-renders branch 2 times, most recently from 71ca232 to 457b29b Compare July 22, 2026 15:20
@yasmoradi
yasmoradi force-pushed the perf/12753-coalesce-wasm-startup-renders branch from 457b29b to 334b830 Compare July 22, 2026 15:37
@yasmoradi
yasmoradi marked this pull request as draft July 22, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor WebAssembly startup re-renders components once per StateHasChanged

1 participant