Skip to content

Commit

Permalink
Merge pull request #1594 from visualize-admin/feat/improvements
Browse files Browse the repository at this point in the history
fix: Disable transitions on initial load
  • Loading branch information
bprusinowski authored Jun 11, 2024
2 parents e9bf51f + 09c2756 commit f5fb913
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/charts/shared/use-size.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "react";

import { useTransitionStore } from "@/stores/transition";
import { useResizeObserver } from "@/utils/use-resize-observer";
import { INIT_SIZE, useResizeObserver } from "@/utils/use-resize-observer";
import { useTimedPrevious } from "@/utils/use-timed-previous";

export type Margins = {
Expand All @@ -32,7 +32,10 @@ export const Observer = ({ children }: { children: ReactNode }) => {
const [ref, width, height] = useResizeObserver<HTMLDivElement>();
const prevWidth = useTimedPrevious(width, RESIZE_DELAY);
const prevHeight = useTimedPrevious(height, RESIZE_DELAY);
const isResizing = prevWidth !== width || prevHeight !== height;
const isResizing =
prevWidth !== width ||
prevHeight !== height ||
(width === INIT_SIZE && height === INIT_SIZE);
const setEnableTransition = useTransitionStore((state) => state.setEnable);
useEffect(() => {
setEnableTransition(!isResizing);
Expand Down
4 changes: 3 additions & 1 deletion app/utils/use-resize-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { useEventCallback } from "@mui/material";
import throttle from "lodash/throttle";
import { useEffect, useRef, useState } from "react";

export const INIT_SIZE = 1;

export const useResizeObserver = <T extends Element>() => {
const roRef = useRef<ResizeObserver>();
const elRef = useRef<T>();
const [size, changeSize] = useState({ width: 1, height: 1 });
const [size, changeSize] = useState({ width: INIT_SIZE, height: INIT_SIZE });

const handleRef = useEventCallback((node: T) => {
if (!node) {
Expand Down

0 comments on commit f5fb913

Please sign in to comment.