mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-26 07:57:10 +00:00
fix: stop leaking a document keydown handler per uninstall-modal dismissal
showUninstallModal bound `keydown.uninstall-modal` on document but only
detached it on the Escape and Confirm paths. Dismissing via Cancel or a
backdrop click called `close()`, which just removed the overlay and left the
handler attached (closing over a now-detached overlay). Each open→cancel
cycle stacked another document-level listener for the page lifetime.
Move the `.off('keydown.uninstall-modal')` into `close()` so every dismissal
path cleans up, and drop the now-redundant explicit detaches.
This commit is contained in:
@@ -129,17 +129,17 @@ function showUninstallModal ({ appName, appTitle, appUid, self, $el_window }) {
|
||||
|
||||
$el_window.append($overlay);
|
||||
|
||||
const close = () => $overlay.remove();
|
||||
const close = () => {
|
||||
$overlay.remove();
|
||||
$(document).off('keydown.uninstall-modal');
|
||||
};
|
||||
|
||||
$overlay.on('click', '.myapps-modal-cancel', close);
|
||||
$overlay.on('click', function (e) {
|
||||
if ( e.target === $overlay[0] ) close();
|
||||
});
|
||||
$(document).on('keydown.uninstall-modal', function (e) {
|
||||
if ( e.key === 'Escape' ) {
|
||||
close();
|
||||
$(document).off('keydown.uninstall-modal');
|
||||
}
|
||||
if ( e.key === 'Escape' ) close();
|
||||
});
|
||||
|
||||
$overlay.on('click', '.myapps-modal-confirm', async function () {
|
||||
@@ -154,7 +154,6 @@ function showUninstallModal ({ appName, appTitle, appUid, self, $el_window }) {
|
||||
console.error('Failed to uninstall app:', err);
|
||||
}
|
||||
close();
|
||||
$(document).off('keydown.uninstall-modal');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user