fix: safari page blank

This commit is contained in:
jialin
2024-11-22 20:16:23 +08:00
parent a6f0f554f0
commit 59d2c5ae3c
3 changed files with 27 additions and 22 deletions
+8 -13
View File
@@ -3,7 +3,7 @@ import {
UseOverlayScrollbarsParams, UseOverlayScrollbarsParams,
useOverlayScrollbars useOverlayScrollbars
} from 'overlayscrollbars-react'; } from 'overlayscrollbars-react';
import React from 'react'; import React, { useEffect } from 'react';
export const overlaySollerOptions: UseOverlayScrollbarsParams = { export const overlaySollerOptions: UseOverlayScrollbarsParams = {
options: { options: {
@@ -52,7 +52,7 @@ export default function useOverlayScroller(options?: any) {
const throttledScroll = React.useCallback( const throttledScroll = React.useCallback(
throttle(() => { throttle(() => {
scrollEventElement.current?.scrollTo?.({ scrollEventElement.current?.scrollTo?.({
top: scrollEventElement.current.scrollHeight, top: scrollEventElement.current?.scrollHeight,
behavior: 'smooth' behavior: 'smooth'
}); });
instanceRef.current?.update?.(); instanceRef.current?.update?.();
@@ -82,10 +82,6 @@ export default function useOverlayScroller(options?: any) {
// scroll to top // scroll to top
const updateScrollerPositionToTop = React.useCallback(() => { const updateScrollerPositionToTop = React.useCallback(() => {
console.log(
' scrollEventElement.current.scrollHeight====',
scrollEventElement.current.scrollHeight
);
scrollEventElement.current?.scrollTo?.({ scrollEventElement.current?.scrollTo?.({
top: 0, top: 0,
behavior: 'auto' behavior: 'auto'
@@ -107,13 +103,6 @@ export default function useOverlayScroller(options?: any) {
if (el) { if (el) {
initialize(el); initialize(el);
initialized.current = true; initialized.current = true;
console.log(
'createInstance===2',
initialized.current,
instanceRef.current,
instance?.(),
instance
);
instanceRef.current = instance?.(); instanceRef.current = instance?.();
scrollEventElement.current = scrollEventElement.current =
instanceRef.current?.elements()?.scrollEventElement; instanceRef.current?.elements()?.scrollEventElement;
@@ -122,6 +111,12 @@ export default function useOverlayScroller(options?: any) {
[initialize, instance] [initialize, instance]
); );
useEffect(() => {
return () => {
instanceRef.current?.destroy?.();
};
}, [instance]);
return { return {
initialize: createInstance, initialize: createInstance,
instance: instanceRef.current, instance: instanceRef.current,
-2
View File
@@ -15,13 +15,11 @@ class ErrorBoundary extends Component<
}; };
} }
// 捕获错误并更新状态
static getDerivedStateFromError(error: any) { static getDerivedStateFromError(error: any) {
console.error('Error caught by Error Boundary:', error); console.error('Error caught by Error Boundary:', error);
return { hasError: true }; return { hasError: true };
} }
// 记录错误信息(可选)
componentDidCatch(error: any, info: any) { componentDidCatch(error: any, info: any) {
console.error('Error caught by Error Boundary:', error); console.error('Error caught by Error Boundary:', error);
console.error(info); console.error(info);
+19 -7
View File
@@ -195,13 +195,25 @@ export default (props: any) => {
}, [initialize]); }, [initialize]);
useEffect(() => { useEffect(() => {
const menuWrap = document.querySelector( const checkAndInitialize = () => {
'.ant-menu.ant-menu-root' const menuWrap = window.document.querySelector(
)?.parentElement; '.ant-menu.ant-menu-root'
if (menuWrap) { )?.parentElement;
initializeMenu(menuWrap); if (menuWrap) {
} try {
}, [initializeMenu]); initializeMenu(menuWrap);
} catch (error) {
console.error('Failed to initialize menu:', error);
}
} else {
console.warn('Menu wrapper not found.');
}
};
const timeout = setTimeout(checkAndInitialize, 500);
return () => clearTimeout(timeout);
}, [initializeMenu, matchedRoute, location]);
const renderMenuHeader = useCallback( const renderMenuHeader = useCallback(
(logo, title) => { (logo, title) => {