Skip to content

Conversation

@andreasgerstmayr
Copy link
Contributor

Currently, when I close a modal dialog (e.g. the beancount file context in the journal view when pressing on the transaction date) and then press the back button in my browser, the modal dialog opens again. If I open a few modal dialogs after another, all of them open again when I click the back button a few times.

With this change, history.back() is called upon closing the modal dialog, therefore removing the modal URL from the browser history. Now, pressing the back button brings me to the previous page, and not the previous modal dialog.

export function closeOverlay(): void {
if (window.location.hash) {
window.history.pushState(null, "", "#");
window.history.back();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is quite right if e.g. the user navigated to the modal from a different page. The "close" button should first and foremost close the overlay and not just act like the back browser back button. I don't think there's an easy way to implement that, since we don't have access to the history...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, if e.g. Google contains a link to http://127.0.0.1:3000/beancount/journal/?time=2025#context-6db7912cb27c36ac197dd5fbf9a9bebc (directly opening the modal), then closing the modal would bring the user back to Google. But in any other case, if the modal is opened from Fava, imho it should work as expected.

Alternatively, what we could do is to not add the modal link to the browser history at all.
E.g. here:

fava/frontend/src/router.ts

Lines 305 to 306 in bf18b83

if (link.getAttribute("href")?.charAt(0) === "#") {
return;
we can use window.history.replaceState() (replace the current URL with the modal URL) and when closing the modal again in
window.history.pushState(null, "", "#");
we can use window.history.replaceState() instead of window.history.pushState() (to replace the current modal URL with the non-modal URL).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When refactoring the router, I tried to get this working in a reliable way and always ran into some cases where jumping in the browser history would screw this up. I'll close this PR for now

@yagebu yagebu closed this Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants