fix(handlers): register the default handlers only when asked - #36
Merged
Merged
Conversation
Importing the package no longer registers the image, video and audio handlers. The server does it from its `viewer-init` init script on every page, and a page the server does not set up calls `registerDefaultHandlers()` itself, as the playground already did. With several copies of the package on one page, each copy registering on import warned "Handler with id X is already registered." about the others. It also made the entry's side effects invisible from a consumer's import line, which is what the review on nextcloud/server#63954 asked to avoid. Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
==========================================
- Coverage 87.84% 87.83% -0.01%
==========================================
Files 36 36
Lines 2477 2475 -2
Branches 519 519
==========================================
- Hits 2176 2174 -2
Misses 297 297
Partials 4 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Importing
@nextcloud/viewerstill registered the image, video and audio handlers as a side effect oflib/index.ts. The server now callsregisterDefaultHandlers()fromcore/src/viewer-init.ts(nextcloud/server#63954), so the import-time call is gone: importing the package registers nothing, the init script does it on every page, and a page the server does not set up (the playground, a standalone host) calls it itself.Relates to nextcloud/server#63954, review nextcloud/server#63954 (review)
Two copies of the package on one page also stopped warning
Handler with id images is already registered.about each other, since only the init script registers now and any later call is a no-op.Important
Breaking for a consumer that imports the package outside a server page and expected the handlers to be there. Those need one
registerDefaultHandlers()call; the README section "Open the viewer programmatically" says so now.Unit tests cover the entry registering nothing until asked, and the call being idempotent. Playwright ran green on chromium only (12 tests), Firefox is not installed locally.
👾 This pull request was assisted by Claude Code, commits carry an
Assisted-bytrailer.