Repository navigation
refactor!: make pdf-viewer page property read-only - #13389
Conversation
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.
This reverts commit ecae83b.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
✅ 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.
|
Slide deck that explains this pull request from its code. Generated 2026-11-11 14:50 UTC |
|
Custom elements APICompared #13389 ( 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
left a comment
There was a problem hiding this comment.
✅ 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.
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.
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.
|
This ticket/PR has been released with Vaadin 25.4.0-alpha7. |



Summary
Makes the
pageproperty of<vaadin-pdf-viewer>read-only. The viewer ownspage: it follows scrolling, the toolbar and links. Applications go to a page withscrollToPage(). This also fixes a crash afterscrollToPage()with a fractional page such as2.5.Follows up on #13384.
What changed
page(property orpageattribute) no longer scrolls and has no effect. UsescrollToPage(page)instead. It also works right after settingsrc, and in a hidden viewer.srcalways resetspageto 1. CallscrollToPage()after settingsrcto open the document at another page.pageis now always a page of the document. Before, an out-of-range or fractional value set by the application stayed inpage.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) threwCannot read properties of undefined (reading 'unscaledWidth').API Changes
Test summary
pagedoes not change the page or scroll.scrollToPage()with0,2.5,10andNaNwarns, does not scroll and keeps the current page.scrollToPage(2.5)fits the pages without an error.scrollToPage()for a page out of range.pagenow usescrollToPage(). All pdf-viewer unit tests pass in Chromium, and lint and type checks are clean.Working on behalf of Serhii