Coalesce component renders during Blazor WebAssembly startup #12753 - #12754
Coalesce component renders during Blazor WebAssembly startup #12753#12754yasmoradi wants to merge 6 commits into
Conversation
WalkthroughChangesStartup render coalescing
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
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.Rendering.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppComponentBase.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppAiChatPanel.razor.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/AppShell.razor.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/Header/Header.razor.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/NavBar.razor.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Home/HomePage.razor.cs
71ca232 to
457b29b
Compare
457b29b to
334b830
Compare
| [AutoInject] private IServiceProvider serviceProvider = default!; | ||
|
|
||
| [AutoInject] protected IStorageService StorageService = default!; | ||
| protected IJSRuntime JSRuntime => field ??= serviceProvider.GetRequiredService<IJSRuntime>(); |
There was a problem hiding this 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)
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!
| 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>(); |
There was a problem hiding this 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.
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!
Summary
Adds an opt-in render-coalescing mechanism to
AppComponentBasethat collapses a burst ofStateHasChangedcalls 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
AppComponentBase.Rendering.cs: overridesShouldRenderto debounce renders during the startup window. Suppressed renders (re)arm a single trailing render so the final startup state is guaranteed to paint. Tunable viaCoalesceRendersDuration(default 3s, measured from app start) andCoalesceRendersWindow(default 300ms quiet period). Only runs whenAppPlatform.IsBrowser; everything else renders normally.AppComponentBase.cs: adds aDisposeRenderCoalescing()partial invoked fromDisposeAsyncso the coalescing timer is always released; the whole feature stays isolated in its own file and compiles away when absent.CoalesceRenders => true) forAppShell,Header,NavBar,HomePage, andAppAiChatPanel.Related Issue
This closes #12753
Summary by CodeRabbit
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.
AppComponentBasedependencies to lazyIServiceProviderresolution.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
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Merge branch 'bitfoundation:develop' int..." | Re-trigger Greptile
Context used: