1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Remove pagehide event listener as it may cause UI to freeze

Pagehide was needed in cluster frame to better handle main frame close/reload situation. But even empty pagehide listener in cluster frame seems to freeze the UI at least on some situations (multiple clusters open).

Beforeunload is not always executed in cluster frame when main frame is reloaded/closed, leaving log files open. To fix that, `stopIpcLoggingInjectable` is introduced to close all log files.

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
This commit is contained in:
Sami Tiilikainen 2023-03-06 16:53:51 +02:00
parent d3cc345cde
commit 42081df811
2 changed files with 48 additions and 25 deletions

View File

@ -0,0 +1,28 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfFrontEndInjectionToken } from "../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import ipcFileLoggerInjectable from "./ipc-file-logger.injectable";
const stopIpcLoggingInjectable = getInjectable({
id: "stop-ipc-logging",
instantiate: (di) => {
const ipcFileLogger = di.inject(ipcFileLoggerInjectable);
return {
id: "stop-ipc-logging",
run: () => {
ipcFileLogger.closeAll();
return undefined;
},
};
},
injectionToken: beforeQuitOfFrontEndInjectionToken,
});
export default stopIpcLoggingInjectable;

View File

@ -2,7 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { once } from "lodash";
import type { Cluster } from "../../../../common/cluster/cluster"; import type { Cluster } from "../../../../common/cluster/cluster";
import type { CatalogEntityRegistry } from "../../../api/catalog/entity/registry"; import type { CatalogEntityRegistry } from "../../../api/catalog/entity/registry";
import type { ShowNotification } from "../../../components/notifications"; import type { ShowNotification } from "../../../components/notifications";
@ -24,22 +23,23 @@ interface Dependencies {
const logPrefix = "[CLUSTER-FRAME]:"; const logPrefix = "[CLUSTER-FRAME]:";
export const initClusterFrame = ({ export const initClusterFrame =
hostedCluster, ({
loadExtensions, hostedCluster,
catalogEntityRegistry, loadExtensions,
frameRoutingId, catalogEntityRegistry,
emitAppEvent, frameRoutingId,
logger, emitAppEvent,
showErrorNotification, logger,
closeFileLogging, showErrorNotification,
}: Dependencies) => closeFileLogging,
}: Dependencies) =>
async (unmountRoot: () => void) => { async (unmountRoot: () => void) => {
// TODO: Make catalogEntityRegistry already initialized when passed as dependency // TODO: Make catalogEntityRegistry already initialized when passed as dependency
catalogEntityRegistry.init(); catalogEntityRegistry.init();
logger.info( logger.info(
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`, `${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`
); );
await requestSetClusterFrameId(hostedCluster.id); await requestSetClusterFrameId(hostedCluster.id);
@ -51,19 +51,17 @@ export const initClusterFrame = ({
// Note that the Catalog might still have unprocessed entities until the extensions are fully loaded. // Note that the Catalog might still have unprocessed entities until the extensions are fully loaded.
when( when(
() => catalogEntityRegistry.items.get().length > 0, () => catalogEntityRegistry.items.get().length > 0,
() => () => loadExtensions(),
loadExtensions(),
{ {
timeout: 15_000, timeout: 15_000,
onError: (error) => { onError: (error) => {
logger.warn( logger.warn("[CLUSTER-FRAME]: error from activeEntity when()", error);
"[CLUSTER-FRAME]: error from activeEntity when()",
error,
);
showErrorNotification("Failed to get KubernetesCluster for this view. Extensions will not be loaded."); showErrorNotification(
"Failed to get KubernetesCluster for this view. Extensions will not be loaded."
);
}, },
}, }
); );
setTimeout(() => { setTimeout(() => {
@ -76,15 +74,12 @@ export const initClusterFrame = ({
}); });
}); });
const onCloseFrame = once(() => { window.addEventListener("beforeunload", () => {
logger.info( logger.info(
`${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`, `${logPrefix} Unload dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`
); );
unmountRoot(); unmountRoot();
closeFileLogging(); closeFileLogging();
}); });
window.addEventListener("beforeunload", onCloseFrame);
window.addEventListener("pagehide", onCloseFrame);
}; };