Skip to content

fix(doc): restore PDF link clicks after pdf.js 6 upgrade#1694

Merged
ahorowitz123 merged 1 commit into
masterfrom
fix-pdf-link-annotations-z-index
Jul 6, 2026
Merged

fix(doc): restore PDF link clicks after pdf.js 6 upgrade#1694
ahorowitz123 merged 1 commit into
masterfrom
fix-pdf-link-annotations-z-index

Conversation

@ahorowitz123

Copy link
Copy Markdown
Contributor

Problem

After the pdfjs-dist 4.3.136 → 6.0.227 upgrade (#1666), external link annotations in PDFs render but are not clickable.

Root cause

pdf.js renders each link as an invisible <a> inside section.linkAnnotation in the .annotationLayer, overlaying the visible text span. All page layers are absolutely-positioned siblings with z-index: auto, so DOM order decides hit-testing.

pdf.js 6 inserts its layers earlier in the page render lifecycle than v4 did, which changes the sibling order:

  • v4 (working): canvasWrapper → ba-Layer--regionCreation → textLayer → annotationLayer — links on top
  • v6 (broken): canvasWrapper → textLayer → annotationLayer → annotationEditorLayer → ba-Layer--regionCreation — the box-annotations region-creation overlay (full-page, pointer-events: auto, swallows clicks via PointerCapture) lands above the links

Fix

Give .annotationLayer z-index: 2 inside .bp-doc: above the region-creation overlay (auto) and textLayer (1), below the box-annotations region/highlight/drawing layers (3) and popups (4). This restores the exact stacking relationships v4 had.

Testing

Verified live against a devpod with both pdf.js versions A/B tested:

  • Link markup is identical in v4 and v6 — regression is purely stacking order
  • With fix: clicking the link opens the target URL in a new tab
  • Existing region/highlight/drawing annotations overlapping a link still win clicks (z-index 3 > 2), matching v4
  • Region-creation mode over a link behaves identically to v4
  • Text selection unaffected
  • stylelint passes; CSS-only change

Note: pdf.js's native annotationEditorLayer (rendered permanently disabled — box-annotations is used instead) now stacks below the link layer. Inert today; revisit if native pdf.js editors are ever enabled.

🤖 Generated with Claude Code

pdfjs-dist 6 inserts its page layers earlier in the render lifecycle
than v4 did, so the box-annotations region-creation overlay (a
full-page pointer-events: auto div) now comes after the
annotationLayer in DOM order and swallows clicks on link
annotations. Give the annotationLayer z-index: 2 to lift links
above the overlay while staying below the box-annotations
region/highlight/drawing layers (z-index: 3) and popups (4),
restoring the same stacking relationships as pdfjs-dist 4.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ahorowitz123 ahorowitz123 requested a review from a team as a code owner July 6, 2026 17:49
@ahorowitz123 ahorowitz123 merged commit 18fec52 into master Jul 6, 2026
7 checks passed
@ahorowitz123 ahorowitz123 deleted the fix-pdf-link-annotations-z-index branch July 6, 2026 19:41
mrscobbler added a commit that referenced this pull request Jul 9, 2026
Revert the pdfjs-dist 6.0.227 bump (#1666) while v6 regressions are
investigated. Restores engines.node >=20.0.0 (the bump only existed
to satisfy pdfjs 6) and removes the annotationLayer z-index
workaround from #1694, which compensated for v6's earlier page-layer
insertion and is unnecessary on v4.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Sophia <1317004+mrscobbler@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants