Skip to content

feat(resizing): Add new performant useResizable hook #91548

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 7 commits into from

Conversation

MichaelSun48
Copy link
Member

Creates a new hook useResizable

useResizable consumes a container ref and updates its width directly, rather than storing and returning a size state like the previous useResizableDrawer, making it feel significantly more performant. It also ensures that the cursor is always attached to the drag handle while dragging, which was an issue with useResizableDrawer. Besides these changes, the API is similar to useResizableDrawer and supports params like onResizeStart, onResizeEnd, and a isHeld return param.

Next steps would be to support vertical resizing, and replace as many usages of useResizableDrawer with this.

Stories entry incoming

@MichaelSun48 MichaelSun48 requested a review from a team May 13, 2025 17:19
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 13, 2025
Copy link

codecov bot commented May 13, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
10287 1 10286 9
View the full list of 1 ❄️ flaky tests
Sentry Application Details Editing an existing public Sentry App with a scope error handles client secret rotation

Flake rate in main: 14.29% (Passed 12 times, Failed 2 times)

Stack Traces | 0.28s run time
TestingLibraryElementError: Unable to find an element with the text: This will be the only time your client secret is visible!. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
...
    at Object.getElementError (.../sentry/sentry/node_modules/@.../dom/dist/config.js:37:19)
    at .../sentry/sentry/node_modules/@.../dom/dist/query-helpers.js:76:38
    at .../sentry/sentry/node_modules/@.../dom/dist/query-helpers.js:52:17
    at .../sentry/sentry/node_modules/@.../dom/dist/query-helpers.js:95:19
    at Object.<anonymous> (.../settings/organizationDeveloperSettings/sentryApplicationDetails.spec.tsx:591:42)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines +44 to +51
/**
* Apply this to the drag handle element to include 'reset' functionality.
*/
onDoubleClick: () => void;
/**
* Attach this to the drag handle element's onMouseDown handler.
*/
onMouseDown: (e: React.MouseEvent) => void;
Copy link
Member

Choose a reason for hiding this comment

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

react aria kinda does these buttonProps it might make sense to have a handleProps if we think they should be applied in a uniform way

const startXRef = useRef<number>(0);
const startWidthRef = useRef<number>(0);

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

might make sense to be a useLayoutEffect so it doesn't appear as the smaller size then the bigger size

? parseInt(localStorage.getItem(sizeStorageKey) ?? '', 10)
: undefined;

ref.current.style.width = `${storedSize ?? initialSize}px`;
Copy link
Member

@scttcper scttcper May 13, 2025

Choose a reason for hiding this comment

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

i think whats difficult about using px values here is what if i resize it while i'm on my big monitor then open it again with a smaller window. could it be too large?

Copy link
Member

Choose a reason for hiding this comment

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

you might consider storing the localstorage value as a % and computing the px value

Copy link
Member

Choose a reason for hiding this comment

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

might depend on what maxValue is for these usecases

@JonasBa
Copy link
Member

JonasBa commented May 13, 2025

@MichaelSun48 can we instead modify the old hook? I would be happy to help you with this and I have even started some work around it.

The reason I am proposing this is because what you have here is exactly how the old hook used to work (I know bc I wrote it initially), but then people ended up adding size state storage to it without me knowing, which made it perform poorly.

If you want, I'd be happy to team up on this and make sure that we only have resizable hook and behaviour in our code.

@JonasBa
Copy link
Member

JonasBa commented May 13, 2025

This is the change in question. It is almost there, but requires me to make a few additional updates to support how size clearing works.

#88170

@MichaelSun48
Copy link
Member Author

@JonasBa yeah for sure! I intended to replace all callsites of the old hook with this new one, but it seems like you've got a headstart on that already in your PR. Should I just take down this PR and help update yours in that case?

@JonasBa
Copy link
Member

JonasBa commented May 13, 2025

I think I would prefer if we change the old hook. Fwiw, that PR of mine cannot be merged yet, as some functionality like the double click and reset is broken in a few places - the usage of this is not tested. Let me put something on the calendar for us this week to look at what needs changing, I'm pretty confident we can get it done quickly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants