-
-
Notifications
You must be signed in to change notification settings - Fork 6
fix(PdfReader): prevent render twice when url is null #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures PdfReader's OnAfterRenderAsync exits early after initializing internal state on first render to prevent duplicate rendering when Url is null, and includes a no-op touch to the project file. Sequence diagram for PdfReader OnAfterRenderAsync first render behaviorsequenceDiagram
actor User
participant Browser
participant BlazorRenderer
participant PdfReader
User->>Browser: Navigate to page with PdfReader
Browser->>BlazorRenderer: Initial render
BlazorRenderer->>PdfReader: OnAfterRenderAsync(firstRender=true)
PdfReader->>PdfReader: Initialize _showToolbar, _enableThumbnails, _fitMode
PdfReader-->>BlazorRenderer: return (early exit, no URL handling)
note over User,Browser: Later, application sets PdfReader.Url
User->>Browser: Trigger state change (e.g., set Url)
Browser->>BlazorRenderer: Re-render PdfReader
BlazorRenderer->>PdfReader: OnAfterRenderAsync(firstRender=false)
PdfReader->>PdfReader: Compare _url and Url
PdfReader->>PdfReader: Perform URL-related render logic once
PdfReader-->>BlazorRenderer: return
Flow diagram for PdfReader OnAfterRenderAsync control logicflowchart TD
A[OnAfterRenderAsync invoked] --> B{firstRender}
B -- yes --> C[Set _showToolbar from ShowToolbar]
C --> D[Set _enableThumbnails from EnableThumbnails]
D --> E[Set _fitMode from FitMode]
E --> F[Return immediately]
B -- no --> G{_url != Url}
G -- yes --> H[Update _url]
H --> I[Execute URL-related render logic]
I --> J[Return]
G -- no --> J[Return]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The early
returninOnAfterRenderAsyncnow skips the subsequent_url != Urllogic on every first render, not just whenUrlis null; consider guarding the early exit with astring.IsNullOrEmpty(Url)(or similar) check so valid URLs still trigger the expected initialization path. - It may be clearer to explicitly separate the
Url-is-null/empty branch from the normal initialization path (e.g., with an early guard at the top ofOnAfterRenderAsync), so the control flow reflects the intent of avoiding double render only when there is no URL.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The early `return` in `OnAfterRenderAsync` now skips the subsequent `_url != Url` logic on every first render, not just when `Url` is null; consider guarding the early exit with a `string.IsNullOrEmpty(Url)` (or similar) check so valid URLs still trigger the expected initialization path.
- It may be clearer to explicitly separate the `Url`-is-null/empty branch from the normal initialization path (e.g., with an early guard at the top of `OnAfterRenderAsync`), so the control flow reflects the intent of avoiding double render only when there is no URL.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in the PdfReader component where rendering would occur twice when the Url parameter is null, by adding an early return statement after initializing state variables on the first render.
Changes:
- Added early return in
OnAfterRenderAsyncafter first render initialization to prevent subsequent execution - Bumped component version from 10.0.25 to 10.0.26
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs | Added return statement after first render initialization to prevent double rendering when Url is null |
| src/components/BootstrapBlazor.PdfReader/BootstrapBlazor.PdfReader.csproj | Version bump to 10.0.26 to reflect the bug fix |
Comments suppressed due to low confidence (1)
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs:231
- Equality checks on floating point values can yield unexpected results.
if (_currentRotation != CurrentRotation)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _showToolbar = ShowToolbar; | ||
| _enableThumbnails = EnableThumbnails; | ||
| _fitMode = FitMode; | ||
| return; |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bug fix prevents double rendering when Url is null, but there are no automated tests to verify this behavior. Consider adding unit tests for the PdfReader component to ensure this issue doesn't regress in the future, especially for the OnAfterRenderAsync lifecycle method with various Url states.
Link issues
fixes #894
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Bug Fixes: