Skip to content

Commit 4412697

Browse files
committed
perf: 性能优化
1 parent 6d7c2e0 commit 4412697

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/components/stateless/OverflowText/index.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import React, { useEffect, useRef, useState, useLayoutEffect } from 'react'
1+
import React, { useEffect, useRef, useState, useLayoutEffect, useMemo } from 'react'
22
import PortalTooltip from '../PortalTooltip'
33
import styles from './index.module.less'
44

55
// SSR-safe useLayoutEffect
66
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
77

8+
const EMPTY_STYLE = {}
9+
const EMPTY_TOOLTIP_PROPS = {}
10+
811
/**
912
* OverflowText
1013
*
@@ -22,15 +25,18 @@ const OverflowText = ({
2225
minWidth = 0,
2326
maxWidth,
2427
className = '',
25-
style = {},
26-
tooltipProps = {},
28+
style = EMPTY_STYLE,
29+
tooltipProps = EMPTY_TOOLTIP_PROPS,
2730
alwaysShow = false,
2831
lines = 0,
2932
onOverflowChange,
3033
}) => {
3134
const elRef = useRef(null)
3235
const [isOverflow, setIsOverflow] = useState(false)
3336

37+
// Stabilize style reference — only re-run effect when style content actually changes
38+
const stableStyleKey = useMemo(() => JSON.stringify(style), [style])
39+
3440
const check = () => {
3541
const el = elRef.current
3642
if (!el) return
@@ -60,7 +66,7 @@ const OverflowText = ({
6066
// Check on mount and updates
6167
useIsomorphicLayoutEffect(() => {
6268
check()
63-
}, [text, lines, maxWidth, style, className])
69+
}, [text, lines, maxWidth, stableStyleKey, className])
6470

6571
useEffect(() => {
6672
const el = elRef.current

src/pages/home/BookLibrary/index.module.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
transform: translateY(6px);
203203
}
204204

205-
// 定位每一段
206205
:global(.segmentGradient .segmentStrip-1) { top: 0%; }
207206
:global(.segmentGradient .segmentStrip-2) { top: calc(100% / 6 * 1); }
208207
:global(.segmentGradient .segmentStrip-3) { top: calc(100% / 6 * 2); }

0 commit comments

Comments
 (0)