Skip to content

feat(viewer): register the pdf handler with @nextcloud/viewer - #1586

Merged
juliusknorr merged 4 commits into
masterfrom
feature/nextcloud-viewer-package
Oct 12, 2026
Merged

juliusknorr merged 4 commits into
masterfrom
feature/nextcloud-viewer-package

Conversation

@skjnldsv

Copy link
Copy Markdown
Member

The viewer app goes away with nextcloud/server#63954, and with it OCA.Viewer.registerHandler and the LoadViewer event this app hangs off, so PDFs stop opening in the viewer on 36. This registers the handler through the @nextcloud/viewer package instead.

Fixes #1572
Depends on nextcloud/server#63954

The handler is a custom element, files-pdfviewer-view, wrapping PDFView, which is still only loaded once a PDF is opened. LoadViewerListener listens to BeforeTemplateRenderedEvent now and adds the registration as an init script, skipping the error page and the pdf.js page the viewer frames. PDFView gets the node the viewer hands over instead of fileList and fileid, and uploads annotations to its encodedSource. The handler id stays pdf, since files_emailviewer looks it up by id.

The richdocuments fallback for a share that hides or forbids the download works as before, but through getViewer().open(files, file, undefined, 'richdocuments'). It only kicks in once richdocuments has a viewer handler, which needs nextcloud/richdocuments#6060: until then it is as if richdocuments were not installed. Reopening like that drops the opener's onClose, nextcloud-libraries/nextcloud-viewer#66 keeps it.

pdf.js decodes its file parameter once, so the iframe gets the encoded dav URL now. With the unencoded one, my file #1.pdf loaded my file and nothing else. That is its own commit; the old code passed source the same way, so it was probably broken before too.

The assets commit adds 467 files and removes 387, most of the new ones being the viewer's own lazy chunks, which every app bundling the package ships.

Checked in a browser against server#63954: opening from Files and from a public link share, saving annotations on test.pdf and my file #1.pdf, and a link share with hidden download, where pdf.js comes up with printing and text selection off. Not checked: the richdocuments handoff, since no richdocuments has a v2 handler yet, and the versions compare view.

👾 This pull request was assisted by Claude Code, commits carry an Assisted-by trailer.

@juliusknorr

Copy link
Copy Markdown
Member

Tried this branch in the richdocuments Cypress run (nextcloud/richdocuments#6142): clicking a PDF downloads it instead of opening the viewer.

The branch bundles @nextcloud/viewer 2.0.0-beta.12, which registers handlers under the handlers_v1 ABI, while server master ships beta.14 with handlers_v2. So the pdf handler ends up in a registry the server never reads. Bumping to beta.14 should fix it, together with renaming tagname to tagName in registerHandler().

Failing run: https://github.com/nextcloud/richdocuments/actions/runs/37293538070

@skjnldsv

skjnldsv commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

@juliusknorr yes, we've have a bump pr for this on server: nextcloud/server#65000

skjnldsv and others added 4 commits October 9, 2026 10:13
The viewer app went away with nextcloud/server#63954, and with it
OCA.Viewer.registerHandler and the LoadViewer event this app hung off,
so PDFs stopped opening in the viewer on 36.

The handler names a custom element, defined from PDFView in onInit, so
the view only loads the first time a PDF is opened. The registration
goes out as an init script on every page but the error page and the
pdf.js page itself. PDFView gets the node the viewer hands over, uploads
annotations to it, and hands a restricted file to richdocuments by id
when richdocuments has a viewer handler to take it.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
pdf.js decodes its file parameter once, so with the unencoded source a
file named "my file #1.pdf" loaded "my file " and nothing else.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
@juliusknorr
juliusknorr merged commit 3dfd230 into master Oct 12, 2026
43 checks passed
@juliusknorr
juliusknorr deleted the feature/nextcloud-viewer-package branch October 12, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate off the OCA.Viewer global before Nextcloud 36

2 participants