Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 10, 2026

Link issues

fixes #894

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Bug Fixes:

  • Avoid triggering a second render pass by exiting early after applying initial toolbar and layout state when no URL is provided.

Copilot AI review requested due to automatic review settings January 10, 2026 02:48
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures 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 behavior

sequenceDiagram
    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
Loading

Flow diagram for PdfReader OnAfterRenderAsync control logic

flowchart 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]
Loading

File-Level Changes

Change Details Files
Add an early return on first render in PdfReader to avoid duplicate render logic execution when Url is null or unchanged.
  • Update OnAfterRenderAsync to return immediately after syncing internal fields with component parameters on firstRender
  • Keep subsequent Url change check logic only for non-first renders
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#894 Fix the PdfReader bug that causes pages to be duplicated / rendered twice after upgrading to version 10.0.24 (likely due to OnAfterRenderAsync running logic twice when Url is null or unchanged).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added the triage label Jan 10, 2026
@bb-auto bb-auto bot added this to the v9.2.0 milestone Jan 10, 2026
@ArgoZhang ArgoZhang merged commit 76a1793 into master Jan 10, 2026
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the fix-pdf branch January 10, 2026 02:48
Copy link

@sourcery-ai sourcery-ai bot left a 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 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

Copilot AI left a 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 OnAfterRenderAsync after 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;
Copy link

Copilot AI Jan 10, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(PdfReader): duplicates pages issue

2 participants