Skip to content

Pages beyond the first few render blank on large PDFs until the viewer is resized #63

Description

@SiKreuz

Describe the bug

On large multi-page PDFs, only the first few pages render correctly. As you scroll further, pages appear blank/white and never paint. Any resize of the viewer — resizing the browser window, or toggling the sidebar/thumbnail panel (which animates the pages container width) — immediately repaints the affected pages correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Render a viewer with RPProvider + default , initialScale={ZoomLevel.PAGE_WIDTH}.
  2. Load a large multi-page PDF (many pages / mixed page sizes).
  3. Scroll down past the first few pages.
  4. See pages render blank/white instead of their content.
  5. Resize the browser window (or toggle the sidebar) — the blank pages immediately render correctly.

Expected behavior
All pages render their content as they scroll into view, without requiring a manual resize.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS 26 (likely independent)
  • Browser: Firefox, Chrome (i think all browsers)

Smartphone (please complete the following information):
Not tested

Additional context

The library version is 2.7.2. RPProvider is used with initialScale={ZoomLevel.PAGE_WIDTH} and the default virtualized <RPPages />.

Likely root cause (from tracing the bundle):

  • <RPPages /> renders through a react-window VariableSizeGrid. Rows that haven't been mounted yet fall back to a single estimatedRowHeight. On tall documents the estimate diverges from the real page heights, so the grid maps scrollTop to the wrong visible range and the pages actually under the viewport are never mounted → blank.
  • ZoomContext derives the page scale from the container width via a ResizeObserver with a ~100ms debounce, and returns 0 while width/height are unset. While the scale is 0, CanvasLayer early-returns and enqueues no render, so those canvases never paint.
  • A resize fires the ResizeObserver(s): AutoSizer pushes fresh width/height into the grid, ZoomContext recomputes a non-zero scale, and the page-dimension change triggers resetAfterIndices(..., shouldForceUpdate: true), which invalidates the cached/estimated heights and forces the correct pages to mount and paint. This is why resizing fixes it.

This looks related to the virtual-scroll / viewport-detection issues previously fixed in #38 and #44, but the failure mode here is blank pages rather than page-count/layout drift.

  • @react-pdf-kit/viewer version: 2.7.2
  • React version: [e.g. 19.x]
  • Bundler: Vite
  • initialScale: ZoomLevel.PAGE_WIDTH
  • Have not yet confirmed against 2.7.3-rc.0 / 2.8.0-beta

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions