Skip to content

feat(trace): Change state priority on trace drawer resize #67885

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
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);
});
Comment on lines +72 to +74
Copy link
Member Author

Choose a reason for hiding this comment

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

keeps the drawer close to the cursor, removes batching

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,
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(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

marks this state update as low priority https://react.dev/reference/react/startTransition

Copy link
Member Author

Choose a reason for hiding this comment

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

this function doesn't seem to exist on 17

setTracePreferences(previousPreferences => {
return {
...previousPreferences,
Expand All @@ -552,7 +545,7 @@ function TraceViewContent(props: TraceViewContentProps) {
: window.innerWidth),
};
});
}, 1000);
});
},
[setTracePreferences]
);
Expand Down