Skip to content

Commit

Permalink
feat(trace): Change state priority on trace drawer resize
Browse files Browse the repository at this point in the history
Fixes the lag from resizing the trace drawer by removing render batching on the size updates and lowering the priority of state updates in a parent component.

fixes getsentry/frontend-tsc#61
  • Loading branch information
scttcper committed Mar 28, 2024
1 parent 31ae2c7 commit d66be81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 4 additions & 1 deletion static/app/utils/useResizableDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useCallback, useLayoutEffect, useRef, useState} from 'react';
import {flushSync} from 'react-dom';

export interface UseResizableDrawerOptions {
/**
Expand Down Expand Up @@ -68,7 +69,9 @@ export function useResizableDrawer(options: UseResizableDrawerOptions): {

const updateSize = useCallback(
(newSize: number) => {
setSize(newSize);
flushSync(() => {
setSize(newSize);
});
options.onResize(newSize);
if (options.sizeStorageKey) {
localStorage.setItem(options.sizeStorageKey, newSize.toString());
Expand Down
13 changes: 3 additions & 10 deletions static/app/views/performance/newTraceDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type React from 'react';
import {
startTransition,

Check failure on line 3 in static/app/views/performance/newTraceDetails/index.tsx

View workflow job for this annotation

GitHub Actions / typescript and lint

Module '"react"' has no exported member 'startTransition'.
useCallback,
useEffect,
useLayoutEffect,
Expand Down Expand Up @@ -59,10 +60,6 @@ import {
} from 'sentry/views/performance/newTraceDetails/traceTabs';
import {VirtualizedViewManager} from 'sentry/views/performance/newTraceDetails/virtualizedViewManager';

import {
cancelAnimationTimeout,
requestAnimationTimeout,
} from '../../../utils/profiling/hooks/useVirtualizedTree/virtualizedTreeUtils';
import Breadcrumb from '../breadcrumb';

import TraceDrawer from './traceDrawer/traceDrawer';
Expand Down Expand Up @@ -535,13 +532,9 @@ function TraceViewContent(props: TraceViewContentProps) {
[setTracePreferences]
);

const resizeAnimationTimeoutRef = useRef<{id: number} | null>(null);
const onDrawerResize = useCallback(
(size: number) => {
if (resizeAnimationTimeoutRef.current !== null) {
cancelAnimationTimeout(resizeAnimationTimeoutRef.current);
}
resizeAnimationTimeoutRef.current = requestAnimationTimeout(() => {
startTransition(() => {
setTracePreferences(previousPreferences => {
return {
...previousPreferences,
Expand All @@ -552,7 +545,7 @@ function TraceViewContent(props: TraceViewContentProps) {
: window.innerWidth),
};
});
}, 1000);
});
},
[setTracePreferences]
);
Expand Down

0 comments on commit d66be81

Please sign in to comment.