Skip to content

feat(PdfReader): support wasm mode#770

Merged
ArgoZhang merged 3 commits intomasterfrom
feat-pdf
Dec 3, 2025
Merged

feat(PdfReader): support wasm mode#770
ArgoZhang merged 3 commits intomasterfrom
feat-pdf

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 3, 2025

Link issues

fixes #769

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

Add support for a new PdfReader stylesheet and defer displaying the toolbar and controls until the viewer is initialized.

New Features:

  • Introduce a dedicated pdf_reader.css stylesheet for the PdfReader component and load it from the JS initializer.

Enhancements:

  • Adjust PdfReader markup and styles so toolbar, controls, and document info are initially hidden and then revealed once initialization completes.
  • Simplify thumbnail-related CSS selectors to use standard class selectors instead of deep combinators.

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

sourcery-ai Bot commented Dec 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds WASM-friendly styling and initialization behavior to the PdfReader component by consolidating CSS, deferring toolbar visibility until JS initialization, and updating the JS loader to reference the new bundled stylesheet.

Sequence diagram for PdfReader WASM initialization and toolbar reveal

sequenceDiagram
    participant BlazorPdfReader as BlazorPdfReaderComponent
    participant JSInterop as JSInterop
    participant PdfReaderJS as PdfReaderJsModule
    participant Document as Document
    participant CssLink as CssLinkLoader

    BlazorPdfReader->>JSInterop: invoke init(id, invoke, options)
    JSInterop->>PdfReaderJS: init(id, invoke, options)
    PdfReaderJS->>CssLink: addLink(./_content/BootstrapBlazor.PdfReader/css/pdf_reader.css)
    CssLink-->>PdfReaderJS: css_loaded
    PdfReaderJS->>Document: getElementById(id)
    Document-->>PdfReaderJS: el
    PdfReaderJS->>PdfReaderJS: addToolbarEventHandlers(el, pdfViewer, invoke, options)
    PdfReaderJS->>Document: querySelectorAll(.invisible) on el
    Document-->>PdfReaderJS: invisibleElements
    PdfReaderJS->>Document: remove class invisible from toolbar, controls, pdf_info
    PdfReaderJS->>BlazorPdfReader: invoke callbacks via invoke (events, status)
Loading

File-Level Changes

Change Details Files
Consolidate PdfReader styles into a shared CSS file and adjust scoping for thumbnail elements.
  • Move component-scoped PdfReader.razor.css content into wwwroot/css/pdf_reader.css and import pdf_viewer.css from there
  • Replace Blazor ::deep selectors with plain class selectors for thumbnail list items and their nested elements to make styles apply in the static CSS file
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.css
src/components/BootstrapBlazor.PdfReader/wwwroot/css/pdf_reader.css
Hide toolbar and info sections until JavaScript initialization completes, then reveal them.
  • Add the invisible CSS class to the main toolbar, control group, and PDF info dialog container in the Razor markup so they start hidden
  • In the JS init path, remove the invisible class from all relevant elements once the toolbar event handlers are wired up
src/components/BootstrapBlazor.PdfReader/PdfReader.razor
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Update JavaScript initialization to load the new bundled PdfReader stylesheet instead of the bare pdf_viewer.css.
  • Change the injected stylesheet URL from pdf_viewer.css to pdf_reader.css so both base viewer styles and component-specific styles are loaded in browser contexts, including WASM
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#769 Enable the PdfReader component to work correctly in WebAssembly (wasm) mode, including loading its styles and initializing the toolbar/controls properly.

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 6a3742f into master Dec 3, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the feat-pdf branch December 3, 2025 01:07
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:

  • Using a generic .invisible class to control initial visibility may conflict with existing utility classes (e.g., Bootstrap’s .invisible) and can be brittle; consider renaming to a more specific, component-scoped class (e.g., .bb-pdf-initially-hidden) to avoid collisions.
  • Hiding the toolbar and document info until JS initialization completes means users with JS disabled or with initialization errors will never see basic controls; consider providing a minimal non-JS fallback or only hiding non-critical pieces to preserve basic usability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using a generic `.invisible` class to control initial visibility may conflict with existing utility classes (e.g., Bootstrap’s `.invisible`) and can be brittle; consider renaming to a more specific, component-scoped class (e.g., `.bb-pdf-initially-hidden`) to avoid collisions.
- Hiding the toolbar and document info until JS initialization completes means users with JS disabled or with initialization errors will never see basic controls; consider providing a minimal non-JS fallback or only hiding non-critical pieces to preserve basic usability.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:374-376` </location>
<code_context>

 const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
     const toolbar = el.querySelector(".bb-view-toolbar");
+    [...el.querySelectorAll('.invisible')].forEach(i => {
+        i.classList.remove('invisible');
+    });

     EventHandler.on(toolbar, "click", '.bb-view-bar', e => {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using a blanket `.invisible` selector may unintentionally affect elements that should remain hidden or be controlled independently.

Removing `invisible` from every descendant of `el` tightly couples toolbar initialization to all other uses of that class in the component. If other elements later use `invisible` for their own lifecycle (e.g., lazy-loaded or conditional content), they’ll be incorrectly made visible here. Instead, target only the toolbar-related elements you intend to reveal, for example:

```js
['.bb-view-toolbar-main.invisible', '.bb-view-controls.invisible', '.bb-view-pdf-info.invisible']
  .forEach(sel => el.querySelectorAll(sel).forEach(i => i.classList.remove('invisible')));
```

This keeps initialization scoped to the relevant UI parts and avoids side effects on unrelated elements.
</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 adds WASM (WebAssembly) mode support to the PdfReader component by addressing CSS scoping and initialization timing issues. The changes involve removing deprecated ::deep CSS selectors, consolidating CSS imports, and implementing a progressive reveal pattern for toolbar elements to prevent layout issues during PDF loading in WASM environments.

  • Removed deprecated ::deep CSS selectors and replaced with standard selectors
  • Added progressive reveal pattern using invisible class for toolbar elements
  • Consolidated CSS loading by importing pdf_viewer.css into pdf_reader.css

Reviewed changes

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

File Description
pdf_reader.css Added @import for pdf_viewer.css and removed deprecated ::deep selectors for thumbnail items
PdfReader.razor.js Changed CSS file reference from pdf_viewer.css to pdf_reader.css and added logic to remove invisible class after initialization
PdfReader.razor Added invisible class to toolbar and info elements to hide them until PDF is loaded
BootstrapBlazor.PdfReader.csproj Bumped version from 10.0.9 to 10.0.10
Comments suppressed due to low confidence (10)

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

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

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

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

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

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

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

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

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

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

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

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

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

  • Unused variable scaleEl.
    const scaleEl = el.querySelector(".bb-view-scale-input");

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

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

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

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

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

  • 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.

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): support wasm mode

2 participants