Skip to content

Commit 3e9f5b2

Browse files
authored
Merge 411fb3b into 0553047
2 parents 0553047 + 411fb3b commit 3e9f5b2

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/Overflow.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,19 @@ function Overflow<ItemType = any>(
302302
// ================================ Render ================================
303303
const displayRest = restReady && !!omittedItems.length;
304304

305-
let suffixStyle: React.CSSProperties = {};
305+
const isFullySSRResponsiveFirstRender =
306+
fullySSR && shouldResponsive && containerWidth === null;
307+
const fullySSRFirstRenderStyle: React.CSSProperties = {
308+
maxWidth: 0,
309+
padding: 0,
310+
margin: 0,
311+
borderWidth: 0,
312+
overflowX: 'hidden',
313+
};
314+
315+
let suffixStyle: React.CSSProperties = isFullySSRResponsiveFirstRender
316+
? fullySSRFirstRenderStyle
317+
: {};
306318
if (suffixFixedStart !== null && shouldResponsive) {
307319
suffixStyle = {
308320
position: 'absolute',
@@ -316,13 +328,22 @@ function Overflow<ItemType = any>(
316328
responsive: shouldResponsive,
317329
component: itemComponent,
318330
invalidate,
331+
style: isFullySSRResponsiveFirstRender
332+
? fullySSRFirstRenderStyle
333+
: undefined,
319334
};
320335

321336
// >>>>> Choice render fun by `renderRawItem`
322337
const internalRenderItemNode = renderRawItem
323338
? (item: ItemType, index: number) => {
324339
const key = getKey(item, index);
325-
340+
const isIdxCheckPass = index <= mergedDisplayCount;
341+
// in `ssr="full"` case, item's `display` will be set to `true` when either condition is met:
342+
// 1) at initial render; 2) its corresponding width is valid and pass the index check
343+
const shouldDisplay = fullySSR
344+
? isFullySSRResponsiveFirstRender ||
345+
(isIdxCheckPass && getItemWidth(index) > 0)
346+
: isIdxCheckPass;
326347
return (
327348
<OverflowContext.Provider
328349
key={key}
@@ -332,7 +353,7 @@ function Overflow<ItemType = any>(
332353
item,
333354
itemKey: key,
334355
registerSize,
335-
display: index <= mergedDisplayCount,
356+
display: shouldDisplay,
336357
}}
337358
>
338359
{renderRawItem(item, index)}
@@ -341,7 +362,13 @@ function Overflow<ItemType = any>(
341362
}
342363
: (item: ItemType, index: number) => {
343364
const key = getKey(item, index);
344-
365+
const isIdxCheckPass = index <= mergedDisplayCount;
366+
// in `ssr="full"` case, item's `display` will be set to `true` when either condition is met:
367+
// 1) at initial render; 2) its corresponding width is valid and pass the index check
368+
const shouldDisplay = fullySSR
369+
? isFullySSRResponsiveFirstRender ||
370+
(isIdxCheckPass && getItemWidth(index) > 0)
371+
: isIdxCheckPass;
345372
return (
346373
<Item
347374
{...itemSharedProps}
@@ -351,7 +378,7 @@ function Overflow<ItemType = any>(
351378
renderItem={mergedRenderItem}
352379
itemKey={key}
353380
registerSize={registerSize}
354-
display={index <= mergedDisplayCount}
381+
display={shouldDisplay}
355382
/>
356383
);
357384
};

tests/__snapshots__/ssr.spec.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ exports[`Overflow.SSR basic 1`] = `
66
>
77
<div
88
class="rc-overflow-item"
9-
style="opacity:1;order:0"
9+
style="opacity:1;order:0;max-width:0;padding:0;margin:0;border-width:0;overflow-x:hidden"
1010
>
1111
Label 0
1212
</div>
1313
<div
1414
class="rc-overflow-item"
15-
style="opacity:1;order:1"
15+
style="opacity:1;order:1;max-width:0;padding:0;margin:0;border-width:0;overflow-x:hidden"
1616
>
1717
Label 1
1818
</div>
1919
<div
2020
aria-hidden="true"
2121
class="rc-overflow-item rc-overflow-item-rest"
22-
style="opacity:0;height:0;overflow-y:hidden;order:9007199254740991;pointer-events:none;position:absolute"
22+
style="opacity:0;height:0;overflow-y:hidden;order:9007199254740991;pointer-events:none;position:absolute;max-width:0;padding:0;margin:0;border-width:0;overflow-x:hidden"
2323
>
2424
+ 0 ...
2525
</div>

0 commit comments

Comments
 (0)