Skip to content

refactor!: make pdf-viewer page property read-only - #13389

Merged
vursen merged 5 commits into
mainfrom
fix/pdf-viewer-fractional-page
Nov 11, 2026
Merged

vursen merged 5 commits into
mainfrom
fix/pdf-viewer-fractional-page

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes the page property of <vaadin-pdf-viewer> read-only. The viewer owns page: it follows scrolling, the toolbar and links. Applications go to a page with scrollToPage(). This also fixes a crash after scrollToPage() with a fractional page such as 2.5.

Follows up on #13384.

What changed

  • Breaking: setting page (property or page attribute) no longer scrolls and has no effect. Use scrollToPage(page) instead. It also works right after setting src, and in a hidden viewer.
  • Breaking: a new src always resets page to 1. Call scrollToPage() after setting src to open the document at another page.
  • page is now always a page of the document. Before, an out-of-range or fractional value set by the application stayed in page.
  • scrollToPage() with a value that is not a page of the document (out of range, 0, a fraction, NaN) logs a warning and does not scroll, and the current page stays as it was. Before, a fraction was kept as the current page, and the next layout (e.g. after a resize) threw Cannot read properties of undefined (reading 'unscaledWidth').
  • The toolbar no longer needs special handling for a page outside the document.

API Changes

// Changed
- page: number;
+ readonly page: number; // setting it has no effect, use scrollToPage()

Test summary

  • Setting page does not change the page or scroll.
  • scrollToPage() with 0, 2.5, 10 and NaN warns, does not scroll and keeps the current page.
  • Resizing after scrollToPage(2.5) fits the pages without an error.
  • A hidden viewer renders its first pages when shown after scrollToPage() for a page out of range.
  • The page field is empty without a document.
  • Tests that set page now use scrollToPage(). All pdf-viewer unit tests pass in Chromium, and lint and type checks are clean.

Working on behalf of Serhii

web-padawan and others added 2 commits November 11, 2026 16:01
Setting page to a fraction such as 2.5 pinned it, and the next layout read a page view that does not exist.
The next and previous page buttons and the NextPage and PrevPage link
actions went to a page such as 3.5 when page was set to 2.5, which only
logged a warning. Round to the pages around the fraction instead.
@web-padawan
web-padawan marked this pull request as ready for review November 11, 2026 14:19

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Nothing to flag — the changes look good.

Risk: 🟢 low — Small fix confined to the experimental, feature-flagged pdf-viewer; for integer pages the arithmetic is provably unchanged, the only behavior that changes is a state that previously threw or warned, and each of the three claims is covered by a test that fails on the pre-fix code.

The viewer owns page: it follows scrolling and links. Applications
now go to a page with scrollToPage(), so page is always a page of the
document. Setting page has no effect.

scrollToPage() with a value that is not a page of the document, e.g.
a fraction, warns and is no longer kept as the current page, as the
next layout read a page view that does not exist.
@vaadin-bot

vaadin-bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Slide deck that explains this pull request from its code.

Generated 2026-11-11 14:50 UTC

@totally-not-ai totally-not-ai Bot changed the title fix: handle fractional page in pdf-viewer refactor!: make pdf-viewer page property read-only Nov 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

@web-padawan web-padawan added the pr-presentation Generates a slide deck of the code changes and posts a comment with a link to it label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Custom elements API

Compared #13389 (51dc813c5c) with 4ead7de23a.

custom-elements.json impact: 1 removed, 1 changed in 1 element
@@ vaadin-pdf-viewer (PdfViewer) @@
-  attribute page: number
-  property page: number [attribute=page]
+  property page: number [readonly]
web-types.json impact: 2 removed in 1 element
@@ vaadin-pdf-viewer @@
-  attribute page: number
-  property page: number

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Nothing to flag — the changes look good.

Risk: 🟡 medium — Breaking public API change — page becomes read-only and a new src always resets it — but it is confined to the experimental, feature-flagged pdf-viewer whose docs state the API may change, and every new behavior path is covered by tests that fail on the pre-change code.

@vursen
vursen enabled auto-merge (squash) November 11, 2026 16:30
@vursen
vursen merged commit bed4888 into main Nov 11, 2026
27 of 31 checks passed
@vursen
vursen deleted the fix/pdf-viewer-fractional-page branch November 11, 2026 17:08
web-padawan added a commit that referenced this pull request Nov 12, 2026
The page property is read-only since #13389, so it is always a page of
the document. Remove the tests of a page out of range.
web-padawan added a commit that referenced this pull request Nov 12, 2026
The page property is read-only since #13389, so it is always a page of
the document. Use scrollToPage() in tests and remove the handling of a
page out of range and of a page set while the viewer is hidden.
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-presentation Generates a slide deck of the code changes and posts a comment with a link to it Released with Vaadin 25.4.0-alpha7

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants