Skip to content

feat(PdfReader): remove async/await getPdfUrl#845

Merged
ArgoZhang merged 3 commits intomasterfrom
feat-backdrop
Dec 18, 2025
Merged

feat(PdfReader): remove async/await getPdfUrl#845
ArgoZhang merged 3 commits intomasterfrom
feat-backdrop

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 18, 2025

Link issues

fixes #844

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

Simplify the PdfReader print and download flow by removing unnecessary async/await usage and improving the document properties backdrop behavior.

Enhancements:

  • Make PdfReader print and download handlers synchronous by eliminating redundant async wrappers around getPdfUrl, downloadPdf, and printPdf.
  • Refine the document properties dialog backdrop by managing its visibility via shared backdrop element and new show/hide helpers, and adjusting related CSS.

Copilot AI review requested due to automatic review settings December 18, 2025 04:56
@bb-auto bb-auto Bot added the enhancement New feature or request label Dec 18, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Dec 18, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Dec 18, 2025

Reviewer's Guide

Refactors the PdfReader client-side logic to remove unnecessary async/await usage for printing and downloading, introduces explicit backdrop show/hide helpers for the document properties dialog, and adjusts the markup/CSS to support a single shared backdrop overlay outside the dialog container.

Sequence diagram for PdfReader toolbar download and print interactions

sequenceDiagram
    actor User
    participant Toolbar
    participant PdfReaderJs
    participant getPdfUrl
    participant Browser

    User->>Toolbar: click bb-view-download
    Toolbar->>PdfReaderJs: downloadPdf(options, fileName)
    PdfReaderJs->>getPdfUrl: getPdfUrl(options, callback)
    alt options.url is set
        getPdfUrl-->>PdfReaderJs: callback(options.url)
    else options.data is set
        getPdfUrl->>Browser: createObjectURL(Blob(options.data))
        Browser-->>getPdfUrl: objectUrl
        getPdfUrl-->>PdfReaderJs: callback(objectUrl)
        getPdfUrl->>Browser: revokeObjectURL(objectUrl)
    end
    PdfReaderJs->>Browser: create <a>, set href, download, click

    User->>Toolbar: click bb-view-print
    Toolbar->>PdfReaderJs: printPdf(el, options)
    PdfReaderJs->>PdfReaderJs: ensure print iframe exists
    PdfReaderJs->>getPdfUrl: getPdfUrl(options, callback)
    alt options.url is set
        getPdfUrl-->>PdfReaderJs: callback(options.url)
    else options.data is set
        getPdfUrl->>Browser: createObjectURL(Blob(options.data))
        Browser-->>getPdfUrl: objectUrl
        getPdfUrl-->>PdfReaderJs: callback(objectUrl)
        getPdfUrl->>Browser: revokeObjectURL(objectUrl)
    end
    PdfReaderJs->>Browser: set iframe.src = url
    Browser-->>PdfReaderJs: iframe.onload
    PdfReaderJs->>Browser: iframe.contentWindow.print()
    PdfReaderJs->>Toolbar: invoke.invokeMethodAsync(Printing)
Loading

File-Level Changes

Change Details Files
Remove unnecessary async/await patterns around getPdfUrl, download, and print flows to make them purely callback-based synchronous wrappers.
  • Change toolbar click handlers for print and download buttons to call printPdf and downloadPdf without awaiting them.
  • Refactor downloadPdf to a non-async function that invokes getPdfUrl and creates/clicks a temporary anchor element without returning a Promise.
  • Refactor printPdf to a non-async function that invokes getPdfUrl, sets iframe src, and triggers print on load without returning a Promise.
  • Refactor getPdfUrl to be non-async and call the provided callback directly, removing await usage and Promise creation.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Introduce explicit backdrop show/hide utilities and adjust dialog/backdrop structure to share a backdrop element outside the info dialog container.
  • Add showBackdrop and hideBackdrop helpers that toggle the .show class on a .bb-view-pdf-backdrop element within the PdfReader root element.
  • Update the document properties toolbar click handler to show the backdrop when opening the info dialog and hide it when closing via the close button.
  • Move the backdrop div out of the .bb-view-pdf-info container in the Razor markup so it is a sibling element, initialized with the invisible class.
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
src/components/BootstrapBlazor.PdfReader/PdfReader.razor
Adjust CSS for the PDF info backdrop to work with the new structure and visibility rules.
  • Define .bb-view-pdf-backdrop styles earlier in the file with absolute positioning, dark background, and z-index, alongside a :not(.show) rule to hide it by default.
  • Remove the old .bb-view-pdf-backdrop rule block that resided after the .bb-view-pdf-info styles to avoid duplication and ensure consistent behavior with the new DOM structure.
src/components/BootstrapBlazor.PdfReader/wwwroot/css/pdf_reader.css

Assessment against linked issues

Issue Objective Addressed Explanation
#844 Refactor PdfReader JavaScript to remove async/await usage from getPdfUrl and its related call sites (e.g., download and print handlers), while preserving existing functionality.

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

@ArgoZhang ArgoZhang merged commit 54fc509 into master Dec 18, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the feat-backdrop branch December 18, 2025 04:56
Copy link
Copy Markdown

@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 there - I've reviewed your changes - here's some feedback:

  • The new .bb-view-pdf-backdrop element is rendered with the invisible class but showBackdrop/hideBackdrop only toggle show, so depending on your CSS for .invisible the backdrop may remain hidden even when show is added; consider either dropping invisible from the markup or explicitly removing/adding it in the show/hide helpers.
  • Now that printPdf is synchronous, the print toolbar handler no longer needs to be async or await the call to invoke.invokeMethodAsync("Printing"); you can simplify this handler to a non-async function.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `.bb-view-pdf-backdrop` element is rendered with the `invisible` class but `showBackdrop`/`hideBackdrop` only toggle `show`, so depending on your CSS for `.invisible` the backdrop may remain hidden even when `show` is added; consider either dropping `invisible` from the markup or explicitly removing/adding it in the show/hide helpers.
- Now that `printPdf` is synchronous, the print toolbar handler no longer needs to be `async` or `await` the call to `invoke.invokeMethodAsync("Printing")`; you can simplify this handler to a non-async function.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.PdfReader/PdfReader.razor:104` </location>
<code_context>
             </div>
         </div>
     </div>
+    <div class="bb-view-pdf-backdrop invisible"></div>
     <div class="bb-view-pdf-info invisible">
-        <div class="bb-view-pdf-backdrop"></div>
</code_context>

<issue_to_address>
**issue (bug_risk):** The backdrop will likely never become visible because it keeps the `invisible` class even when `.show` is toggled.

`bb-view-pdf-backdrop` is rendered with `class="bb-view-pdf-backdrop invisible"`, but `showBackdrop(el)` only adds `show` and never removes `invisible`. Since `.invisible` (in Bootstrap) uses `visibility: hidden !important`, it will override `.show`, so the backdrop likely never appears. Please either drop `invisible` from the markup or have `showBackdrop`/`hideBackdrop` toggle `invisible` instead of/along with `show`.
</issue_to_address>

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
Copy Markdown

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 refactors the PDF reader component by removing unnecessary async/await from the getPdfUrl function and its callers, as the operations are synchronous. Additionally, it improves the backdrop functionality for the document properties dialog by extracting backdrop management into dedicated helper functions and restructuring the HTML for better separation of concerns.

Key Changes:

  • Removed async/await from getPdfUrl, downloadPdf, and printPdf functions since these operations don't require asynchronous handling
  • Added showBackdrop and hideBackdrop helper functions to manage the backdrop display
  • Restructured the backdrop element in the markup to be a sibling of the info dialog rather than nested within it

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
PdfReader.razor.js Removed async/await from getPdfUrl and related functions; added showBackdrop/hideBackdrop helper functions for backdrop management
PdfReader.razor Moved backdrop element from inside bb-view-pdf-info to be a sibling element for better DOM structure
pdf_reader.css Repositioned .bb-view-pdf-backdrop CSS rule to appear before .bb-view-pdf-info for better logical ordering
BootstrapBlazor.PdfReader.csproj Bumped version from 10.0.21 to 10.0.22
Comments suppressed due to low confidence (9)

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:216

  • Unused variable title.
    const title = el.querySelector('.bb-view-pdf-dialog-title');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:217

  • Unused variable author.
    const author = el.querySelector('.bb-view-pdf-dialog-author');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:218

  • Unused variable subject.
    const subject = el.querySelector('.bb-view-pdf-dialog-subject');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:219

  • Unused variable keywords.
    const keywords = el.querySelector('.bb-view-pdf-dialog-keywords');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:223

  • Unused variable modified.
    const modified = el.querySelector('.bb-view-pdf-dialog-modified');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:243

  • Unused variable webview.
    const webview = el.querySelector('.bb-view-pdf-dialog-view');

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:738

  • The initial value of v is unused, since it is always overwritten.
    let v = 100;

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:191

  • Avoid automated semicolon insertion (90% of all statements in the enclosing function have an explicit semicolon).
            })

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:661

  • Avoid automated semicolon insertion (91% of all statements in the enclosing function have an explicit semicolon).
    delete el.widths

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

Comment on lines +805 to 806
callback(url);
window.URL.revokeObjectURL(url);
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is invoked synchronously, but the URL is immediately revoked on the next line. This creates a race condition where the URL may be revoked before it's fully used by the callback (e.g., before the download anchor is clicked or the iframe loads). Consider making the callback asynchronous or using a timeout/event listener to ensure the URL is used before being revoked.

Copilot uses AI. Check for mistakes.
await printPdf(el, options);
printPdf(el, options);
await invoke.invokeMethodAsync("Printing");
})
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid automated semicolon insertion (95% of all statements in the enclosing function have an explicit semicolon).

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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(PdfReader): remove async/await getPdfUrl

2 participants