Skip to content

Commit

Permalink
Disable prompt dialog for the home page (#141)
Browse files Browse the repository at this point in the history
Currently, whenever one tries to navigate away from an appmode app,
(e.g. by clicking a URL link, or closing a tab), a confirmation dialog always pops up,
even without any real interaction with the page.
This is especially annoying for the home app.

The confirmation dialog comes from the jupyter notebook,
because Appmode always copies the notebook and executes it,
which leaves it in an "unsaved" state from the jupyter notebook point of
view.

Here we simply override the 'onbefereunload' event handler that
is defined.

For now this fix is only applied to the home page.
If there are no issues, we could fix this globally by implementing
the fix directly in the Appmode itself, specifically here:
https://github.com/oschuett/appmode/blob/3998dc1a6d61f06581fe818351e70860c26c442a/appmode/static/main.js#L136

Note that in the past, the `onbeforeunload` event used to be
overrided in Appmode, but later the handler was moved to the `unload`
event, which exposed the confirmation dialog.
See oschuett/appmode@8665aa6

The unload event handler in Appmode takes care of the cleanup,
i.e. shutting down the kernel. Since we're modifying a different event,
we should be safe (and I have tested that sessions get cleaned properly).

See #133 for further technical details and discussion.
  • Loading branch information
danielhollas authored Mar 16, 2023
1 parent 39cc819 commit ed851ef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"%%javascript\n",
"IPython.OutputArea.prototype._should_scroll = function(lines) {\n",
" return false;\n",
"}\n",
"if (document.getElementById('appmode-busy')) {\n",
" window.onbeforeunload = function() {return}\n",
"}"
]
},
Expand Down Expand Up @@ -108,7 +111,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -122,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ed851ef

Please sign in to comment.