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: Maximum update depth exceeded error #1561

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
03e225b
fix: Maximum update depth exceeded error
Dzuming Sep 13, 2024
ac56691
provide window margin
Dzuming Sep 13, 2024
9183aa1
fix window init position
Dzuming Sep 13, 2024
76a3ec6
fix window init position
Dzuming Sep 13, 2024
6e2f052
fix window init position
Dzuming Sep 13, 2024
53e07ac
fix window init position
Dzuming Sep 13, 2024
45e9151
fix window init position
Dzuming Sep 13, 2024
a3d1570
fix window init position
Dzuming Sep 13, 2024
86e4587
fix window init position
Dzuming Sep 13, 2024
d75c585
fix window init position
Dzuming Sep 13, 2024
4c026f1
fix window init position
Dzuming Sep 13, 2024
79968f1
Merge branch 'dev' into NU-1807-fix-Maximum-update-depth-exceeded-error
Dzuming Nov 22, 2024
9b7be74
Merge remote-tracking branch 'origin/NU-1807-fix-Maximum-update-depth…
Dzuming Nov 22, 2024
ece213f
Merge branch 'refs/heads/dev' into NU-1807-fix-Maximum-update-depth-e…
Dzuming Nov 27, 2024
8a36b97
update
Dzuming Nov 27, 2024
69ac98f
fix: Maximum update depth exceeded error
Dzuming Sep 13, 2024
11288e3
chore(release): 1.9.0 [skip ci]
semantic-release-bot Sep 16, 2024
36c9845
chore: ci tweak
JulianWielga Sep 16, 2024
c5d0302
chore: bump github actions plugin
mslabek Nov 14, 2024
981e7e2
chore: change animation library to react-transition-state
Dzuming Nov 19, 2024
52f3c67
fix: issue with manually change window size
Dzuming Nov 19, 2024
b5e1dba
chore(release): 1.9.1-beta.1 [skip ci]
semantic-release-bot Nov 25, 2024
b27a10b
fix: revert change animation library
Dzuming Nov 27, 2024
fe927e9
Revert "revert change animation library"
Dzuming Nov 27, 2024
063f4fc
chore(release): 1.9.1-beta.2 [skip ci]
semantic-release-bot Nov 27, 2024
2eb8b3f
Merge remote-tracking branch 'origin/NU-1807-fix-Maximum-update-depth…
Dzuming Nov 27, 2024
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
29 changes: 7 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"react-hotkeys-hook": "4.5.0",
"react-inspector": "6.0.2",
"react-rnd": "10.4.13",
"react-transition-group": "4.4.5",
"react-transition-state": "2.2.0",
"reselect": "5.1.0",
"rooks": "7.14.1"
},
Expand Down
12 changes: 7 additions & 5 deletions src/components/ModalMask.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { css, cx } from "@emotion/css";
import React, { forwardRef, RefObject } from "react";
import React from "react";
import { rgba } from "../rgba";
import { useModalMaskTheme } from "../themeHooks";
import { WindowId } from "../types";
import { useTransition } from "./TransitionProvider";

export const ModalMask = forwardRef(({ zIndex }: { zIndex?: number }, ref: RefObject<HTMLDivElement>): JSX.Element => {
export const ModalMask = ({ zIndex, id }: { zIndex?: number; id: WindowId }): JSX.Element => {
const modalMaskTheme = useModalMaskTheme();
const modalMaskClass = css({
top: 0,
Expand All @@ -13,7 +15,7 @@ export const ModalMask = forwardRef(({ zIndex }: { zIndex?: number }, ref: RefOb
position: "fixed",
background: rgba("black", 0.6),
});
return <div ref={ref} className={cx(modalMaskClass, modalMaskTheme)} style={{ zIndex }} />;
});
const { getTransitionStyle } = useTransition();

ModalMask.displayName = "ModalMask";
return <div className={cx(modalMaskClass, modalMaskTheme, ...getTransitionStyle(id))} style={{ zIndex }} />;
};
77 changes: 77 additions & 0 deletions src/components/TransitionProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { createContext, PropsWithChildren, useCallback, useContext } from "react";
import { useTransitionMap } from "react-transition-state";
import { defaultFadeAnimation, FadeInAnimation } from "./getFadeInAnimation";
import { WindowId } from "../types";

const TRANSITION_TIMEOUT = 100;
const transitionsAnimationTime = new Map<string, number>();
const TransitionContext = createContext<{
startTransition: (id: string) => Promise<boolean>;
finishTransition: (id: string) => Promise<boolean>;
getTransitionStyle: (id: string, fadeInAnimation?: FadeInAnimation) => string[];
}>(null);

export const TransitionProvider = ({ children }: PropsWithChildren) => {
const transition = useTransitionMap({
timeout: TRANSITION_TIMEOUT,
exit: true,
preExit: false,
allowMultiple: true,
});

const getTransitionStyle = useCallback(
(id: WindowId, fadeInAnimation: FadeInAnimation = defaultFadeAnimation) => {
transitionsAnimationTime.set(id, fadeInAnimation.animationTime * 1000);
const transitionItem = transition.stateMap.get(id);
const entered = transitionItem.status === "entered" && fadeInAnimation.entered;
const exited = transitionItem.status === "exited" && fadeInAnimation.exited;

return [fadeInAnimation.mounted, entered, exited];
},
[transition.stateMap],
);

const startTransition = useCallback(
(id: WindowId) => {
return new Promise<boolean>((resolve) => {
transition.setItem(id);
transition.toggle(id, true);
const transitionAnimationTime = transitionsAnimationTime.get(id);

setTimeout(() => {
resolve(true);
}, TRANSITION_TIMEOUT + transitionAnimationTime);
});
},
[transition],
);

const finishTransition = useCallback(
(id: WindowId) => {
return new Promise<boolean>((resolve) => {
transition.toggle(id, false);
const transitionAnimationTime = transitionsAnimationTime.get(id);
setTimeout(() => {
transition.deleteItem(id);
transitionsAnimationTime.delete(id);
resolve(true);
}, TRANSITION_TIMEOUT + transitionAnimationTime);
});
},
[transition],
);

return (
<TransitionContext.Provider value={{ startTransition, finishTransition, getTransitionStyle }}>{children}</TransitionContext.Provider>
);
};

export const useTransition = () => {
const context = useContext(TransitionContext);

if (!context) {
throw new Error();
}

return context;
};
19 changes: 11 additions & 8 deletions src/components/WindowManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppTheme } from "../AppTheme";
import { WindowManagerContextProvider } from "../context";
import { ContentGetter } from "./window/WindowContent";
import { WindowsContainer } from "./WindowsContainer";
import { TransitionProvider } from "./TransitionProvider";

const defaultTheme = {
backgroundOpacity: 0.9,
Expand Down Expand Up @@ -34,13 +35,15 @@ export function WindowManager<K extends number | string = any>({
...props
}: WindowManagerProps<K>): JSX.Element {
return (
<WindowManagerContextProvider>
<div {...props}>
{children}
<ThemeProvider theme={(outerTheme = {}) => defaultsDeep(theme, outerTheme, defaultTheme)}>
<WindowsContainer contentGetter={contentGetter} />
</ThemeProvider>
</div>
</WindowManagerContextProvider>
<TransitionProvider>
<WindowManagerContextProvider>
<div {...props}>
{children}
<ThemeProvider theme={(outerTheme = {}) => defaultsDeep(theme, outerTheme, defaultTheme)}>
<WindowsContainer contentGetter={contentGetter} />
</ThemeProvider>
</div>
</WindowManagerContextProvider>
</TransitionProvider>
);
}
18 changes: 4 additions & 14 deletions src/components/WindowsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { flatMap } from "lodash";
import React, { useRef } from "react";
import { createPortal } from "react-dom";
import { CSSTransition, TransitionGroup } from "react-transition-group";
import { useWindowManager } from "../hooks";
import { defaultFadeAnimation } from "./getFadeInAnimation";
import { ModalMask } from "./ModalMask";
import { Window } from "./window/Window";
import { ContentGetter } from "./window/WindowContent";
Expand All @@ -16,22 +14,14 @@ interface WindowsContainerProps {

export function WindowsContainer({ container = document.body, contentGetter }: WindowsContainerProps): JSX.Element {
const { windows } = useWindowManager();
const modalMaskRef = useRef<HTMLDivElement>();
const windowRef = useRef<HTMLDivElement>();

return createPortal(
<TransitionGroup component={WindowsViewport}>
<WindowsViewport>
{flatMap(windows, (d, index) => [
d.isModal && (
<CSSTransition nodeRef={modalMaskRef} key={`${d.id}/mask`} timeout={250} classNames={defaultFadeAnimation}>
<ModalMask ref={modalMaskRef} key={`${d.id}/mask`} zIndex={index} />
</CSSTransition>
),
<CSSTransition nodeRef={windowRef} key={d.id} timeout={250} classNames={defaultFadeAnimation}>
<Window ref={windowRef} data={d} contentGetter={contentGetter} />
</CSSTransition>,
d.isModal && <ModalMask zIndex={index} key={`${d.id}/mask`} id={d.id} />,
<Window key={d.id} data={d} contentGetter={contentGetter} />,
]).filter(Boolean)}
</TransitionGroup>,
</WindowsViewport>,
container,
);
}
14 changes: 5 additions & 9 deletions src/components/getFadeInAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { css } from "@emotion/css";

export const getFadeInAnimation = (t = 0.25) => ({
enter: css({
animationTime: t,
mounted: css({
opacity: 0,
}),
enterActive: css({
opacity: 1,
transition: `opacity ${t}s ease-in-out`,
pointerEvents: "none",
}),
exit: css({
entered: css({
opacity: 1,
}),
exitActive: css({
exited: css({
opacity: 0,
transition: `opacity ${t}s ease-in-out`,
pointerEvents: "none",
}),
});

export type FadeInAnimation = ReturnType<typeof getFadeInAnimation>;
export const defaultFadeAnimation = getFadeInAnimation();
export const fastFadeAnimation = getFadeInAnimation(0.15);
40 changes: 17 additions & 23 deletions src/components/window/SnapMask.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
import { useTheme } from "@emotion/react";
import React, { useRef } from "react";
import { CSSTransition, TransitionGroup } from "react-transition-group";
import React from "react";
import { rgba } from "../../rgba";
import { fastFadeAnimation } from "../getFadeInAnimation";
import { Box } from "./useSnapAreas";

export const SnapMask = ({ previewBox }: { previewBox: Box }) => {
const nodeRef = useRef<HTMLDivElement>(null);
const {
colors,
spacing: { baseUnit },
} = useTheme();

return (
<TransitionGroup>
<>
{previewBox && (
<CSSTransition nodeRef={nodeRef} timeout={250} classNames={fastFadeAnimation}>
<div
ref={nodeRef}
style={{
boxSizing: "border-box",
position: "fixed",
zIndex: 10,
background: rgba(colors.focusColor, 0.25),
border: `${Math.round(baseUnit / 3)}px solid ${colors?.focusColor}`,
top: previewBox.y,
left: previewBox.x,
width: previewBox.width,
height: previewBox.height,
transition: "all .15s ease-in-out",
}}
/>
</CSSTransition>
<div
style={{
boxSizing: "border-box",
position: "fixed",
zIndex: 10,
background: rgba(colors.focusColor, 0.25),
border: `${Math.round(baseUnit / 3)}px solid ${colors?.focusColor}`,
top: previewBox.y,
left: previewBox.x,
width: previewBox.width,
height: previewBox.height,
transition: "all .15s ease-in-out",
}}
/>
)}
</TransitionGroup>
</>
);
};
8 changes: 4 additions & 4 deletions src/components/window/Window.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, RefObject, useCallback } from "react";
import React, { useCallback } from "react";
import { useWindowManager, useWindowZoom } from "../../hooks";
import { WindowWithOrder } from "../../types";
import { ContentGetter, WindowContent } from "./WindowContent";
Expand All @@ -9,7 +9,7 @@ export interface WindowProps {
contentGetter: ContentGetter;
}

export const Window = forwardRef(({ data, contentGetter }: WindowProps, ref: RefObject<HTMLDivElement>): JSX.Element => {
export const Window = ({ data, contentGetter }: WindowProps): JSX.Element => {
const { isResizable, isStatic, focusParent, id, order, shouldCloseOnEsc } = data;

const { focus: onFocus, close: onClose } = useWindowManager(id);
Expand All @@ -31,7 +31,7 @@ export const Window = forwardRef(({ data, contentGetter }: WindowProps, ref: Ref
height={data.height}
minWidth={data.minWidth}
minHeight={data.minHeight}
ref={ref}
id={data.id}
layoutData={{
width: data.width,
height: data.height,
Expand All @@ -43,6 +43,6 @@ export const Window = forwardRef(({ data, contentGetter }: WindowProps, ref: Ref
<WindowContent contentGetter={contentGetter} data={data} close={onClose} zoom={onToggleZoom} isMaximized={zoom} />
</WindowFrame>
);
});
};

Window.displayName = "Window";
Loading
Loading