Skip to content

Coalesce component renders during Blazor WebAssembly startup #12753 - #12754

Open
yasmoradi wants to merge 6 commits into
bitfoundation:developfrom
yasmoradi:perf/12753-coalesce-wasm-startup-renders
Open

Coalesce component renders during Blazor WebAssembly startup #12753#12754
yasmoradi wants to merge 6 commits 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.

Greptile Summary

This PR introduces opt-in, browser-only startup render coalescing for selected shell, navigation, home, and chat components, with timer cleanup during component disposal.

  • Debounces suppressed startup renders into a trailing render.
  • Enables coalescing for five high-level components.
  • Converts AppComponentBase dependencies to lazy IServiceProvider resolution.

Confidence Score: 4/5

The PR appears safe to merge after addressing the non-blocking dependency-injection convention and documentation consistency concerns.

The render-coalescing paths have disposal and trailing-render safeguards, and no current blocking runtime failure was established; the accepted issues concern the service-locator refactor and its stale documentation.

Files Needing Attention: src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs

Important Files Changed

Filename Overview
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.Rendering.cs Adds the startup-window ShouldRender debounce, trailing timer render, and disposal guard; no concrete blocking failure was established.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs Integrates timer cleanup but also replaces direct component injection with repository-disallowed service-location and leaves related documentation stale.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppAiChatPanel.razor.cs Opts the chat panel into browser startup render coalescing.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppShell.razor.cs Opts the application shell into browser startup render coalescing.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/Header/Header.razor.cs Opts header state updates into browser startup render coalescing.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/NavBar.razor.cs Opts navigation rendering into browser startup render coalescing.
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Home/HomePage.razor.cs Coalesces startup renders produced as the home-page statistics requests complete.

Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs:11-13
**Avoid component service location**

The new lazy dependency properties replace direct `[AutoInject]` declarations with repeated `serviceProvider.GetRequiredService<T>()` calls. This hides the component's dependencies behind a service locator and conflicts with the repository convention requiring component dependencies to use `[AutoInject]`.

### Issue 2
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs:13-19
**Synchronize component injection documentation**

Converting these dependencies from `[AutoInject]` fields to lazy getter-only properties leaves the Boilerplate component documentation showing the removed declarations as the `AppComponentBase` pattern. Update the associated documentation so template consumers are not directed to an implementation that no longer matches the generated source.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Merge branch 'bitfoundation:develop' int..." | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Context used:

  • Context used - src/Templates/Boilerplate/Bit.Boilerplate/AGENTS.m... (source)

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: coalescing component renders during Blazor WebAssembly startup.
✨ 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
@yasmoradi
yasmoradi marked this pull request as ready for review August 11, 2026 16:50
Comment on lines +11 to +13
[AutoInject] private IServiceProvider serviceProvider = default!;

[AutoInject] protected IStorageService StorageService = default!;
protected IJSRuntime JSRuntime => field ??= serviceProvider.GetRequiredService<IJSRuntime>();

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 Avoid component service location

The new lazy dependency properties replace direct [AutoInject] declarations with repeated serviceProvider.GetRequiredService<T>() calls. This hides the component's dependencies behind a service locator and conflicts with the repository convention requiring component dependencies to use [AutoInject].

Context Used: src/Templates/Boilerplate/Bit.Boilerplate/AGENTS.m... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs
Line: 11-13

Comment:
**Avoid component service location**

The new lazy dependency properties replace direct `[AutoInject]` declarations with repeated `serviceProvider.GetRequiredService<T>()` calls. This hides the component's dependencies behind a service locator and conflicts with the repository convention requiring component dependencies to use `[AutoInject]`.

**Context Used:** src/Templates/Boilerplate/Bit.Boilerplate/AGENTS.m... ([source](https://github.com/bitfoundation/bitplatform/blob/develop/src/Templates/Boilerplate/Bit.Boilerplate/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Comment on lines +13 to +19
protected IJSRuntime JSRuntime => field ??= serviceProvider.GetRequiredService<IJSRuntime>();

[AutoInject] protected JsonSerializerOptions JsonSerializerOptions = default!;
protected IStorageService StorageService => field ??= serviceProvider.GetRequiredService<IStorageService>();

[AutoInject] protected TimeProvider TimeProvider = default!;
protected JsonSerializerOptions JsonSerializerOptions => field ??= serviceProvider.GetRequiredService<JsonSerializerOptions>();

protected TimeProvider TimeProvider => field ??= serviceProvider.GetRequiredService<TimeProvider>();

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 Synchronize component injection documentation

Converting these dependencies from [AutoInject] fields to lazy getter-only properties leaves the Boilerplate component documentation showing the removed declarations as the AppComponentBase pattern. Update the associated documentation so template consumers are not directed to an implementation that no longer matches the generated source.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cs
Line: 13-19

Comment:
**Synchronize component injection documentation**

Converting these dependencies from `[AutoInject]` fields to lazy getter-only properties leaves the Boilerplate component documentation showing the removed declarations as the `AppComponentBase` pattern. Update the associated documentation so template consumers are not directed to an implementation that no longer matches the generated source.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

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