nextcloud / nextcloud/viewer

Clear handlers consumed by eager initialization before DOMContentLoaded replay

Open Beginner friendly
#3,362 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
119
Forks
72
Avg merge
18h 42m
Merged PRs (30d)
24

Description

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: https://github.com/nextcloud/viewer/pull/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/init.ts and compare eager consumption of window._oca_viewer_handlers with the DOMContentLoaded bridge in src/views/Viewer.vue. Verify the existing source tests for eager registration, later queued handlers, missing Maps, invalid components, and duplicate IDs. Done means consumed entries are not replayed, later entries still work, and genuine invalid or duplicate registrations remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.