GenericDialog registers an unload listener that has no effect

Open Beginner friendly
#2,772 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
66/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
frontend

Research direction

Read lib/components/GenericDialog.vue and trace the dialog lifecycle hooks that register and remove the unload listener. Decide whether the dialog should warn before navigation or whether the listener should be removed; the issue offers both options. Done means the ineffective listener and its unload policy violation are addressed, with behavior consistent while a dialog is open.

Written by the indexing model from the issue text.

Description

bug
Description

Moved from nextcloud/server#65093 (issues can't be transferred between organizations).

lib/components/GenericDialog.vue registers an unload listener while a generic dialog (e.g. getDialogBuilder() / the delete confirmation in Files) is open:

const handleUnload = () => `${props.name}: ${props.text}`
onMounted(() => window.addEventListener('unload', handleUnload))
onUnmounted(() => window.removeEventListener('unload', handleUnload))

The return value of an unload handler is ignored, so the listener has no effect. Chrome is phasing out unload and blocks it by default on more and more sites, which logs a violation every time such a dialog is opened:

[Violation] Permissions policy violation: unload is not allowed in this document.

It was probably meant to be a beforeunload handler that warns before leaving the page while a dialog is open.

Suggestion

Either switch to beforeunload with event.preventDefault() (if the warning is wanted) or remove the listener.

Reported for @nextcloud/dialogs 7.5.0 as used by Nextcloud 35; still present on main.

Dominant language
TypeScript
Stars
19
Forks
10
Avg merge
17h 4m
Merged PRs (30d)
30

Getting set up

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.

More from nextcloud-libraries/nextcloud-dialogs

All issues in nextcloud-libraries/nextcloud-dialogs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.