Skip to content

Commit

Permalink
fix(core): sidebar shakes unexpectedly during init on mobile (toevery…
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Oct 21, 2024
1 parent 3ca052c commit 90ef12e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/frontend/core/src/modules/app-sidebar/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ export function AppSidebar({ children }: PropsWithChildren) {
const hovering = useLiveData(appSidebarService.hovering$) && open !== true;
const resizing = useLiveData(appSidebarService.resizing$);
const [deferredHovering, setDeferredHovering] = useState(false);
const [initialized, setInitialized] = useState(false);

useEffect(() => {
if (BUILD_CONFIG.isElectron) {
setInitialized(true);
return;
}
const shouldFloating = window.matchMedia(
`(max-width: ${floatingMaxWidth}px)`
).matches;

appSidebarService.setSmallScreenMode(shouldFloating);
setInitialized(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (open) {
// if open, we don't need to show the floating sidebar
Expand Down Expand Up @@ -90,7 +106,6 @@ export function AppSidebar({ children }: PropsWithChildren) {
}

const dOnResize = debounce(onResize, 50);
onResize();
window.addEventListener('resize', dOnResize);
return () => {
window.removeEventListener('resize', dOnResize);
Expand Down Expand Up @@ -147,6 +162,10 @@ export function AppSidebar({ children }: PropsWithChildren) {
};
}, [appSidebarService, resizing, sidebarState, width]);

if (!initialized) {
return null;
}

return (
<>
<ResizePanel
Expand Down

0 comments on commit 90ef12e

Please sign in to comment.