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:
parent
d3cc345cde
commit
42081df811
28
packages/core/src/main/logger/stop-ipc-logging.injectable.ts
Normal file
28
packages/core/src/main/logger/stop-ipc-logging.injectable.ts
Normal 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;
|
||||
@ -2,7 +2,6 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* 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 { CatalogEntityRegistry } from "../../../api/catalog/entity/registry";
|
||||
import type { ShowNotification } from "../../../components/notifications";
|
||||
@ -24,22 +23,23 @@ interface Dependencies {
|
||||
|
||||
const logPrefix = "[CLUSTER-FRAME]:";
|
||||
|
||||
export const initClusterFrame = ({
|
||||
hostedCluster,
|
||||
loadExtensions,
|
||||
catalogEntityRegistry,
|
||||
frameRoutingId,
|
||||
emitAppEvent,
|
||||
logger,
|
||||
showErrorNotification,
|
||||
closeFileLogging,
|
||||
}: Dependencies) =>
|
||||
export const initClusterFrame =
|
||||
({
|
||||
hostedCluster,
|
||||
loadExtensions,
|
||||
catalogEntityRegistry,
|
||||
frameRoutingId,
|
||||
emitAppEvent,
|
||||
logger,
|
||||
showErrorNotification,
|
||||
closeFileLogging,
|
||||
}: Dependencies) =>
|
||||
async (unmountRoot: () => void) => {
|
||||
// TODO: Make catalogEntityRegistry already initialized when passed as dependency
|
||||
catalogEntityRegistry.init();
|
||||
|
||||
logger.info(
|
||||
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`,
|
||||
`${logPrefix} Init dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`
|
||||
);
|
||||
|
||||
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.
|
||||
when(
|
||||
() => catalogEntityRegistry.items.get().length > 0,
|
||||
() =>
|
||||
loadExtensions(),
|
||||
() => loadExtensions(),
|
||||
{
|
||||
timeout: 15_000,
|
||||
onError: (error) => {
|
||||
logger.warn(
|
||||
"[CLUSTER-FRAME]: error from activeEntity when()",
|
||||
error,
|
||||
);
|
||||
logger.warn("[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(() => {
|
||||
@ -76,15 +74,12 @@ export const initClusterFrame = ({
|
||||
});
|
||||
});
|
||||
|
||||
const onCloseFrame = once(() => {
|
||||
window.addEventListener("beforeunload", () => {
|
||||
logger.info(
|
||||
`${logPrefix} Unload dashboard, clusterId=${(hostedCluster.id)}, frameId=${frameRoutingId}`,
|
||||
`${logPrefix} Unload dashboard, clusterId=${hostedCluster.id}, frameId=${frameRoutingId}`
|
||||
);
|
||||
|
||||
unmountRoot();
|
||||
closeFileLogging();
|
||||
});
|
||||
|
||||
window.addEventListener("beforeunload", onCloseFrame);
|
||||
window.addEventListener("pagehide", onCloseFrame);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user