fix: register handler directly with ViewerService when available#3068
Closed
fix: register handler directly with ViewerService when available#3068
Conversation
When an app (e.g. richdocuments) calls registerHandler() from the @nextcloud/viewer package, the handler is stored in the global window._oca_viewer_handlers Map. These handlers are only bridged into the ViewerService (and thus into OCA.Viewer.mimetypes) by a DOMContentLoaded listener in Viewer.vue. Since all Nextcloud scripts are loaded with the defer attribute, there is a race window between the file list rendering and DOMContentLoaded firing. If the files app finishes rendering before the bridge runs, viewerAction's enabled() check reads OCA.Viewer.mimetypes before document mimetypes have been added — the viewer action is disabled and the download action takes over, causing documents to be downloaded instead of opened in Collabora/the viewer. Fix this by also registering the handler directly with the ViewerService when it is already initialized. Because viewer-init runs before other apps' init scripts (both are deferred, viewer registers its LoadViewer listener first), OCA.Viewer is guaranteed to exist when richdocuments' init-viewer script calls registerHandler(). Duplicate registration is harmless — ViewerService.registerHandler() already rejects handlers whose id is already known. Signed-off-by: Andras Timar <andras.timar@collabora.com>
Member
Author
|
This PR did not fix the bug. :( |
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.
When an app (e.g. richdocuments) calls registerHandler() from the @nextcloud/viewer package, the handler is stored in the global window._oca_viewer_handlers Map. These handlers are only bridged into the ViewerService (and thus into OCA.Viewer.mimetypes) by a DOMContentLoaded listener in Viewer.vue.
Since all Nextcloud scripts are loaded with the defer attribute, there is a race window between the file list rendering and DOMContentLoaded firing. If the files app finishes rendering before the bridge runs, viewerAction's enabled() check reads OCA.Viewer.mimetypes before document mimetypes have been added — the viewer action is disabled and the download action takes over, causing documents to be downloaded instead of opened in Collabora/the viewer.
Fix this by also registering the handler directly with the ViewerService when it is already initialized. Because viewer-init runs before other apps' init scripts (both are deferred, viewer registers its LoadViewer listener first), OCA.Viewer is guaranteed to exist when richdocuments' init-viewer script calls registerHandler(). Duplicate registration is harmless — ViewerService.registerHandler() already rejects handlers whose id is already known.