Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 9, 2026

Link issues

fixes #897

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

Ensure PdfReader applies the configured FitMode when initializing the PDF viewer.

Bug Fixes:

  • Pass the PdfReader FitMode value as its description string to the client options so it is correctly recognized by the viewer.
  • Use the fit mode value from the options object in the JavaScript viewer initialization to set the current scale.

Copilot AI review requested due to automatic review settings January 9, 2026 00:32
@bb-auto bb-auto bot added the bug Something isn't working label Jan 9, 2026
@bb-auto bb-auto bot added this to the v9.2.0 milestone Jan 9, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how PdfReader’s FitMode is passed from the .NET component to the JavaScript viewer and fixes its usage during pages initialization so the configured fit mode is properly applied.

Sequence diagram for PdfReader FitMode initialization flow

sequenceDiagram
    participant BlazorApp
    participant PdfReaderComponent
    participant JSRuntime
    participant PdfReaderJs
    participant PdfViewer

    BlazorApp->>PdfReaderComponent: Render PdfReader
    PdfReaderComponent->>PdfReaderComponent: InvokeInitAsync()
    PdfReaderComponent->>PdfReaderComponent: FitMode.ToDescriptionString()
    PdfReaderComponent->>JSRuntime: InvokeAsync Init(options with FitMode string)
    JSRuntime->>PdfReaderJs: initPdfReader(options)
    PdfReaderJs->>PdfViewer: create pdfViewer with options
    PdfReaderJs->>PdfReaderJs: addEventBus(el, pdfViewer, eventBus, invoke, options)
    PdfReaderJs->>PdfReaderJs: eventBus.on(pagesinit)
    PdfViewer-->>PdfReaderJs: pagesinit
    PdfReaderJs->>PdfReaderJs: if options.fitMode
    PdfReaderJs->>PdfViewer: currentScaleValue = options.fitMode
Loading

Class diagram for PdfReader FitMode option handling

classDiagram
    class PdfReaderComponent {
        string Url
        object _data
        string FitMode
        bool EnableThumbnails
        int CurrentPage
        bool TriggerPagesInit
        Task InvokeInitAsync()
    }

    class PdfReaderOptions {
        string Url
        object Data
        string FitMode
        bool EnableThumbnails
        int CurrentPage
        bool TriggerPagesInit
    }

    class PdfReaderJsModule {
        void initPdfReader(string elementId, PdfReaderOptions options)
    }

    class PdfViewer {
        string currentScaleValue
        int pagesCount
    }

    PdfReaderComponent ..> PdfReaderOptions : builds
    PdfReaderComponent ..> PdfReaderJsModule : uses
    PdfReaderJsModule ..> PdfViewer : configures
    PdfReaderOptions --> PdfViewer : options.fitMode applied to currentScaleValue
Loading

File-Level Changes

Change Details Files
Ensure the PdfReader component passes a string description of FitMode to the client instead of the enum value.
  • Update initialization payload to serialize FitMode using ToDescriptionString() before sending to JavaScript
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Fix JavaScript PdfReader initialization to use the fit mode option from the provided options object during pagesinit.
  • Replace incorrect reference to a non-existent fitMode variable with options.fitMode when setting pdfViewer.currentScaleValue on pagesinit
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#897 Ensure PdfReader FitMode works correctly after upgrade (no runtime error; configured FitMode value is correctly passed from .NET to JS and applied on pages initialization).
#897 Restore thumbnail functionality so clicking on thumbnails shows page previews in a left-side list and navigates to the corresponding page. The PR only changes how FitMode is passed and used (C# to JS) and does not modify any code related to thumbnail rendering, thumbnail click handling, or navigation.
#897 Fix PDF rendering and export issues so single-page documents are not duplicated and the Download action produces a valid, non-corrupted PDF file. The changes are limited to FitMode handling in PdfReader.razor.cs and PdfReader.razor.js; there are no changes affecting page count/rendering logic or the download/export implementation.

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

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:

  • Passing FitMode.ToDescriptionString() through to JS couples behavior to the enum’s description attributes; consider using a stable enum name or explicit mapping so refactors of display text don’t silently break the viewer integration.
  • The if (options.fitMode) guard in pagesinit relies on a truthy check; if a valid fit mode could be an empty string or other falsy value, consider an explicit null/undefined check instead to avoid skipping the scale assignment.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Passing `FitMode.ToDescriptionString()` through to JS couples behavior to the enum’s description attributes; consider using a stable enum name or explicit mapping so refactors of display text don’t silently break the viewer integration.
- The `if (options.fitMode)` guard in `pagesinit` relies on a truthy check; if a valid fit mode could be an empty string or other falsy value, consider an explicit null/undefined check instead to avoid skipping the scale assignment.

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 where the FitMode parameter was not working correctly in the PdfReader component. The issue was caused by two problems: the JavaScript code referenced an undefined variable instead of the options object, and the C# code was passing an enum value instead of its string representation.

  • Fixed JavaScript to use options.fitMode instead of undefined fitMode variable
  • Fixed C# to convert the enum to its string description using ToDescriptionString()

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
PdfReader.razor.js Corrected variable reference from fitMode to options.fitMode in the event handler
PdfReader.razor.cs Added .ToDescriptionString() conversion to pass the enum as a string to JavaScript
BootstrapBlazor.PdfReader.csproj Bumped version from 10.0.24 to 10.0.25 for bug fix release

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ArgoZhang ArgoZhang merged commit 2c38c0f into master Jan 9, 2026
2 checks passed
@ArgoZhang ArgoZhang deleted the fix-pdf branch January 9, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(PdfReader): fitMode is not work

2 participants