Skip to content

Persist sidebar width and other improvements#1987

Open
axelboc wants to merge 2 commits intomainfrom
resizable-panels
Open

Persist sidebar width and other improvements#1987
axelboc wants to merge 2 commits intomainfrom
resizable-panels

Conversation

@axelboc
Copy link
Contributor

@axelboc axelboc commented Mar 18, 2026

I'm replacing react-reflex with react-resizable-panels, a much more modern and featureful library.

With a very reasonable amount of code, we get the following features:

  • The sidebar width is persisted to local storage and restored on initial mount or when toggling the sidebar.
  • Resizing the sidebar down to a certain point collapses it automatically; it can then be re-expanded by dragging the splitter.
  • Double-clicking on the splitter resizes the sidebar to its default size.
  • The sidebar is fully accessible — it can be resized and collapsed/expanded with the keyboard.
Screencast.from.2026-03-18.10-03-54.webm
Screencast.from.2026-03-18.10-04-27.webm

I made the splitter a bit more subtle than before, but it still has a 6px target area. I tried to replicate the style of splitters in VS Code: it expands on hover after a slight delay.

The main challenge is that react-sizable-panels provides an uncontrolled API. Because of this, it was a bit tricky to maintain the local isSidebarOpen state in sync (for the toggle sidebar button, breadcrumbs, etc.) while also continuing to support the sidebarOpen prop (which, if you recall, allows to render the viewer with the sidebar collapsed by default when embedded in the Data Portal).

Comment on lines +16 to +17
await expect
.element(page.getByRole('treeitem', { name: 'source.h5' }))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has to be async because of the local isSidebarOpen state synchronisation.

data-fullscreen-root
data-allow-dark-mode={disableDarkMode ? undefined : ''}
orientation="vertical"
data-sidebar-collapsed={!isSidebarOpen || undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to actually hide the content of the sidebar with CSS when the sidebar is collapsed.

Comment on lines +56 to +58
const { defaultLayout, onLayoutChanged } = useDefaultLayout({
id: 'h5web:layout',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hook provides local storage persistence.

(isNowOpen && !isSidebarOpen) ||
(!isNowOpen && isSidebarOpen)
) {
setSidebarOpen(isNowOpen);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The condition is to avoid unnecessary re-renders while resizing.

@@ -1,3 +1,2 @@
/* Global app styles for demo */
@import 'react-reflex/styles.css';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No more global styles 🎉

setupFiles: 'src/setupTests.ts',
restoreMocks: true,
pool: 'threads',
testTimeout: 10_000,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's 15s by default, which I find to be quite long when debugging failing tests locally. Don't want to set it too low, though, even if our longest test lasts only about 4s.

@axelboc
Copy link
Contributor Author

axelboc commented Mar 18, 2026

/approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant