Clear handlers consumed by eager initialization before DOMContentLoaded replay
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:
- Put a valid viewer handler in the global Map before
viewer-initexecutes. - Execute eager initialization: the handler becomes available synchronously.
- Fire the existing
DOMContentLoadedbridge: 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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