fix(core): sidebar shakes unexpectedly during init on mobile (#8506)

https://github.com/user-attachments/assets/4b2791fb-073b-4653-bf2b-d04653bde3c8
This commit is contained in:
JimmFly 2024-10-21 05:13:27 +00:00
parent 3ca052c55f
commit 90ef12eaca
No known key found for this signature in database
GPG Key ID: 126E0320FEB0D05C

View File

@ -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
@ -90,7 +106,6 @@ export function AppSidebar({ children }: PropsWithChildren) {
}
const dOnResize = debounce(onResize, 50);
onResize();
window.addEventListener('resize', dOnResize);
return () => {
window.removeEventListener('resize', dOnResize);
@ -147,6 +162,10 @@ export function AppSidebar({ children }: PropsWithChildren) {
};
}, [appSidebarService, resizing, sidebarState, width]);
if (!initialized) {
return null;
}
return (
<>
<ResizePanel