perf(frontend): replace blank Suspense fallbacks with Spin, switch to matchMedia hook, add virtual table scrolling (#6187)
- routes.tsx, LazyMount.tsx: replace Suspense fallback={null} with Spin
loader so page transitions and lazy modals never show blank content
- useMediaQuery.ts: switch from resize event to matchMedia change event,
eliminating state updates on every pixel drag; export MOBILE_BREAKPOINT_PX
- SubPage.tsx: drop duplicate inline isMobile logic (7 lines), use shared
useMediaQuery(576) (2 lines)
- ClientsPage, InboundList, HostList, NodeList: add virtual + scroll.y to
Table for viewport-only DOM rendering of large datasets
This commit is contained in:
1 parent
0f14ce7551
commit
8e7fb144ee
8 files changed
+42
-20
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { Suspense, useEffect, useState, type ReactNode } from 'react';
|
||||
import { Spin } from 'antd';
|
||||
|
||||
interface LazyMountProps {
|
||||
when: boolean;
|
||||
@@ -10,7 +11,7 @@ interface LazyMountProps {
|
||||
// thereafter, so React.lazy modals get loaded on demand but their close
|
||||
// animations still play out. Pair with `lazy(() => import(...))` modal imports
|
||||
// on heavy list pages to keep the initial bundle small.
|
||||
export default function LazyMount({ when, fallback = null, children }: LazyMountProps) {
|
||||
export default function LazyMount({ when, fallback = <Spin />, children }: LazyMountProps) {
|
||||
const [mounted, setMounted] = useState(when);
|
||||
useEffect(() => {
|
||||
if (when && !mounted) setMounted(true);
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const MOBILE_BREAKPOINT_PX = 768;
|
||||
export const MOBILE_BREAKPOINT_PX = 768;
|
||||
|
||||
/**
|
||||
* Tracks whether the viewport is narrower than `breakpoint`.
|
||||
*
|
||||
* Uses the native `matchMedia` change event instead of the `resize` event so
|
||||
* that state updates fire only when the query actually flips, not on every
|
||||
* pixel change during a window drag.
|
||||
*/
|
||||
export function useMediaQuery(breakpoint: number = MOBILE_BREAKPOINT_PX) {
|
||||
const [isMobile, setIsMobile] = useState<boolean>(() => window.innerWidth <= breakpoint);
|
||||
const query = `(max-width: ${breakpoint}px)`;
|
||||
const [isMobile, setIsMobile] = useState<boolean>(() =>
|
||||
typeof window !== 'undefined' ? window.matchMedia(query).matches : false,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const onResize = () => setIsMobile(window.innerWidth <= breakpoint);
|
||||
window.addEventListener('resize', onResize);
|
||||
return () => window.removeEventListener('resize', onResize);
|
||||
}, [breakpoint]);
|
||||
const mql = window.matchMedia(query);
|
||||
const onChange = (e: MediaQueryListEvent) => setIsMobile(e.matches);
|
||||
mql.addEventListener('change', onChange);
|
||||
setIsMobile(mql.matches);
|
||||
return () => mql.removeEventListener('change', onChange);
|
||||
}, [query]);
|
||||
|
||||
return { isMobile };
|
||||
}
|
||||
@@ -1350,7 +1350,8 @@ export default function ClientsPage() {
|
||||
rowSelection={rowSelection}
|
||||
pagination={tablePagination}
|
||||
size="small"
|
||||
scroll={{ x: 1200 }}
|
||||
scroll={{ x: 1200, y: 'calc(100vh - 380px)' }}
|
||||
virtual
|
||||
onChange={onTableChange}
|
||||
locale={{
|
||||
emptyText: (
|
||||
|
||||
Loaded 3 of 8 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user