The best way to control Claude Code, Codex and more from any computer or phone
perf(web): sidebar drags restyle only the sidebar (#17659)
maria committed
Oct 9, 2026 at 22:51 UTC
033866c7aa55c53593ca31538f7d8ac99fdfe0fd
1 file changed
+23
-9
apps/web/src/components/ui/sidebar.tsx
+23
-9
@@ -369,9 +369,6 @@ function SidebarRail({
369
const suppressClickRef = React.useRef(false);
370
const resolvedResizable = sidebarInstance?.resizable ?? null;
371
const latestResizable = React.useRef(resolvedResizable);
372
- React.useLayoutEffect(() => {
373
- latestResizable.current = resolvedResizable;
374
- }, [resolvedResizable]);
372
const canResize = resolvedResizable !== null && open;
373
const railLabel = canResize ? "Resize Sidebar" : "Toggle Sidebar";
374
const railTitle = canResize ? "Drag to resize sidebar" : "Toggle Sidebar";
@@ -390,14 +387,22 @@ function SidebarRail({
387
sidebarContainer.getBoundingClientRect().width,
388
resolvedResizable,
389
);
393
- const transitionTargets = [
390
+ // Drag frames write width to the gap and container only. Changing the
391
+ // inherited --sidebar-width on the wrapper restyles the whole app, so it is
392
+ // written once when the drag commits.
393
+ const widthTargets = [
394
sidebarRoot.querySelector<HTMLElement>("[data-slot='sidebar-gap']"),
395
sidebarContainer,
396
].filter((element): element is HTMLElement => element !== null);
397
- transitionTargets.forEach((element) => {
397
+ const setTargetWidth = (value: number) => {
398
+ widthTargets.forEach((element) => {
399
+ element.style.setProperty("width", `${value}px`);
400
+ });
401
+ };
402
+ widthTargets.forEach((element) => {
403
element.style.setProperty("transition-duration", "0ms");
404
});
400
- wrapper.style.setProperty("--sidebar-width", `${width}px`);
405
+ setTargetWidth(width);
406
407
return {
408
width,
@@ -416,12 +421,13 @@ function SidebarRail({
421
wrapper,
422
}) ?? true;
423
if (accepted) {
419
- wrapper.style.setProperty("--sidebar-width", `${nextWidth}px`);
424
+ setTargetWidth(nextWidth);
425
width = nextWidth;
426
}
427
return width;
428
},
429
finish(finalWidth, moved) {
430
+ wrapper.style.setProperty("--sidebar-width", `${finalWidth}px`);
431
suppressClickRef.current = moved;
432
const options = latestResizable.current;
433
if (options?.storageKey) {
@@ -434,12 +440,20 @@ function SidebarRail({
440
options?.onResize?.(finalWidth);
441
},
442
cleanup() {
437
- transitionTargets.forEach((element) => {
443
+ widthTargets.forEach((element) => {
444
+ element.style.removeProperty("width");
445
element.style.removeProperty("transition-duration");
446
});
447
},
448
};
442
- });
449
+ // Toggling the sidebar cancels a drag so the inline width never pins a
450
+ // collapsed sidebar open.
451
+ }, String(open));
452
+ React.useLayoutEffect(() => {
453
+ latestResizable.current = resolvedResizable;
454
+ // Bounds follow the window; keep an active drag's inline width inside them.
455
+ resize.refresh();
456
+ }, [resolvedResizable]);
457
458
const handleClick = React.useCallback(
459
(event: React.MouseEvent<HTMLButtonElement>) => {