Skip to content

Clear handlers consumed by eager initialization before DOMContentLoaded replay #3362

Description

@Trockeneis617

Repository: https://github.com/nextcloud/viewer

src/init.ts eagerly registers handlers from window._oca_viewer_handlers, but leaves the Map populated. The DOMContentLoaded listener in src/views/Viewer.vue then registers those same handlers again. ViewerService rejects the duplicate IDs and logs errors during normal navigation.

Verified against the files in the Nextcloud v33.0.6 and v33.0.8 tags and stable33 revision c83b93333a27ca12f6f9c120e6e3079720716b1c. This concerns handlers present before eager initialization; it does not claim to cover every later registration sequence.

Reproduction:

  1. Put a valid viewer handler in the global Map before viewer-init executes.
  2. Execute eager initialization: the handler becomes available synchronously.
  3. Fire the existing DOMContentLoaded bridge: the same ID is registered again and rejected.

Proposed change in src/init.ts:

 if (window._oca_viewer_handlers) {
 	window._oca_viewer_handlers.forEach(handler => window.OCA.Viewer.registerHandler(handler))
+	window._oca_viewer_handlers.clear()
 }

Clear the existing Map after consuming it, preserving its identity and accepting entries queued later. Genuine duplicate or invalid registrations must continue to be rejected.

Validation: extracted source tests cover eager registration, later queued handlers, missing Map, invalid components and genuine duplicate IDs. A Chromium navigation with this change plus independent Text/Theming corrections completed without the prior console errors. That was a local response-substitution comparison, not a rebuilt release test.

Related: #3068 discusses the eager-registration motivation; that PR is closed and unmerged as checked on 2026-09-07. This report addresses replay of already-consumed entries while preserving synchronous initialization.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions