Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #1625 #1702

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions frontend/layout/lib/layoutModelHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LayoutModel } from "./layoutModel";
import { LayoutNode, NodeModel, TileLayoutContents } from "./types";

const layoutModelMap: Map<string, LayoutModel> = new Map();
const timeoutMap: Map<string, NodeJS.Timeout> = new Map();

export function getLayoutModelForTab(tabAtom: Atom<Tab>): LayoutModel {
const tabData = globalStore.get(tabAtom);
Expand Down Expand Up @@ -73,25 +74,26 @@ export function useDebouncedNodeInnerRect(nodeModel: NodeModel): CSSProperties {
const isResizing = useAtomValue(nodeModel.isResizing);
const prefersReducedMotion = useAtomValue(atoms.prefersReducedMotionAtom);
const [innerRect, setInnerRect] = useState<CSSProperties>();
const [innerRectDebounceTimeout, setInnerRectDebounceTimeout] = useState<NodeJS.Timeout>();

const setInnerRectDebounced = useCallback(
(nodeInnerRect: CSSProperties) => {
clearInnerRectDebounce();
setInnerRectDebounceTimeout(
setTimeout(() => {
setInnerRect(nodeInnerRect);
}, animationTimeS * 1000)
);
const timeout = setTimeout(() => {
setInnerRect(nodeInnerRect);
}, animationTimeS * 1000);
timeoutMap.set(nodeModel.blockId, timeout);
},
[animationTimeS]
);
const clearInnerRectDebounce = useCallback(() => {
if (innerRectDebounceTimeout) {
clearTimeout(innerRectDebounceTimeout);
setInnerRectDebounceTimeout(undefined);
const clearInnerRectDebounce = function () {
if (timeoutMap.has(nodeModel.blockId)) {
const innerRectDebounceTimeout = timeoutMap.get(nodeModel.blockId);
if (innerRectDebounceTimeout) {
clearTimeout(innerRectDebounceTimeout);
}
timeoutMap.delete(nodeModel.blockId);
}
}, [innerRectDebounceTimeout]);
};
Comment on lines +88 to +96
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add cleanup on component unmount.

The timeout needs to be cleared when the component unmounts to prevent memory leaks and potential state updates on unmounted components.

Add a cleanup effect:

+    useEffect(() => {
+        return () => clearInnerRectDebounce();
+    }, []);

Committable suggestion skipped: line range outside the PR's diff.


useEffect(() => {
if (prefersReducedMotion || isMagnified || isResizing) {
Expand Down