Skip to content

Commit c4a03fb

Browse files
committed
fix: ssr should fully display
1 parent c3de61f commit c4a03fb

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/Overflow.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function Overflow<ItemType = any>(
9090

9191
const createUseState = useBatchFrameState();
9292

93+
const fullySSR = ssr === 'full'
94+
9395
const [containerWidth, setContainerWidth] = createUseState<number>(null);
9496
const mergedContainerWidth = containerWidth || 0;
9597

@@ -103,7 +105,15 @@ function Overflow<ItemType = any>(
103105
const [suffixWidth, setSuffixWidth] = createUseState(0);
104106
const [suffixFixedStart, setSuffixFixedStart] = useState<number>(null);
105107

106-
const [displayCount, setDisplayCount] = useState(0);
108+
const [displayCount, setDisplayCount] = useState(null);
109+
const mergedDisplayCount = React.useMemo(() => {
110+
if (displayCount === null && fullySSR) {
111+
return Number.MAX_SAFE_INTEGER;
112+
}
113+
114+
return displayCount || 0;
115+
}, [displayCount, containerWidth]);
116+
107117
const [restReady, setRestReady] = useState(false);
108118

109119
const itemPrefixCls = `${prefixCls}-item`;
@@ -125,7 +135,7 @@ function Overflow<ItemType = any>(
125135
let items = data;
126136

127137
if (isResponsive) {
128-
if (containerWidth === null && ssr === 'full') {
138+
if (containerWidth === null && fullySSR) {
129139
items = data;
130140
} else {
131141
items = data.slice(
@@ -142,10 +152,10 @@ function Overflow<ItemType = any>(
142152

143153
const omittedItems = useMemo(() => {
144154
if (isResponsive) {
145-
return data.slice(displayCount + 1);
155+
return data.slice(mergedDisplayCount + 1);
146156
}
147157
return data.slice(mergedData.length);
148-
}, [data, mergedData, isResponsive, displayCount]);
158+
}, [data, mergedData, isResponsive, mergedDisplayCount]);
149159

150160
// ================================= Item =================================
151161
const getKey = useCallback(
@@ -299,7 +309,7 @@ function Overflow<ItemType = any>(
299309
item,
300310
itemKey: key,
301311
registerSize,
302-
display: index <= displayCount,
312+
display: index <= mergedDisplayCount,
303313
}}
304314
>
305315
{renderRawItem(item, index)}
@@ -318,15 +328,15 @@ function Overflow<ItemType = any>(
318328
renderItem={mergedRenderItem}
319329
itemKey={key}
320330
registerSize={registerSize}
321-
display={index <= displayCount}
331+
display={index <= mergedDisplayCount}
322332
/>
323333
);
324334
};
325335

326336
// >>>>> Rest node
327337
let restNode: React.ReactNode;
328338
const restContextProps = {
329-
order: displayRest ? displayCount : Number.MAX_SAFE_INTEGER,
339+
order: displayRest ? mergedDisplayCount : Number.MAX_SAFE_INTEGER,
330340
className: `${itemPrefixCls}-rest`,
331341
registerSize: registerOverflowSize,
332342
display: displayRest,
@@ -375,7 +385,7 @@ function Overflow<ItemType = any>(
375385
{suffix && (
376386
<Item
377387
{...itemSharedProps}
378-
order={displayCount}
388+
order={mergedDisplayCount}
379389
className={`${itemPrefixCls}-suffix`}
380390
registerSize={registerSuffixSize}
381391
display

tests/__snapshots__/ssr.spec.tsx.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ exports[`Overflow.SSR basic 1`] = `
1010
>
1111
Label 0
1212
</div>
13+
<div
14+
class="rc-overflow-item"
15+
style="opacity:1;order:1"
16+
>
17+
Label 1
18+
</div>
1319
<div
1420
aria-hidden="true"
1521
class="rc-overflow-item rc-overflow-item-rest"

tests/ssr.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Overflow.SSR', () => {
3131
it('basic', () => {
3232
const wrapper = render(
3333
<Overflow<ItemType>
34-
data={getData(1)}
34+
data={getData(2)}
3535
renderItem={renderItem}
3636
maxCount="responsive"
3737
ssr="full"

0 commit comments

Comments
 (0)