Fix navigate with replace when there are open dialogs (#23268)

This commit is contained in:
Petar Petrov
2024-12-12 10:25:33 +02:00
committed by GitHub
parent 18cce45b88
commit 93947d76a2
2 changed files with 17 additions and 19 deletions

View File

@@ -14,23 +14,20 @@ export interface NavigateOptions {
data?: any;
}
export const navigate = async (path: string, options?: NavigateOptions) =>
new Promise<boolean>((resolve) => {
// need to wait for history state to be updated in case a dialog was closed before calling navigate
export const navigate = async (path: string, options?: NavigateOptions) => {
const { history } = mainWindow;
if (history.state?.dialog) {
const closed = await closeAllDialogs();
if (!closed) {
// eslint-disable-next-line no-console
console.warn("Navigation blocked, because dialog refused to close");
return false;
}
}
return new Promise<boolean>((resolve) => {
// need to wait for history state to be updated in case a dialog was closed
setTimeout(async () => {
const { history } = mainWindow;
let replace = options?.replace || false;
if (history.state?.dialog) {
const closed = await closeAllDialogs();
if (!closed) {
// eslint-disable-next-line no-console
console.warn("Navigation blocked, because dialog refused to close");
resolve(false);
return;
}
// if there were open dialogs, we discard the current state
replace = true;
}
const replace = options?.replace || false;
if (__DEMO__) {
if (replace) {
@@ -57,3 +54,4 @@ export const navigate = async (path: string, options?: NavigateOptions) =>
resolve(true);
});
});
};