@@ -17,6 +17,7 @@ import StickyContext from '../context/StickyContext';
17
17
import HoverContext from '../context/HoverContext' ;
18
18
import type { HoverContextProps } from '../context/HoverContext' ;
19
19
import warning from 'rc-util/lib/warning' ;
20
+ import PerfContext from '../context/PerfContext' ;
20
21
21
22
/** Check if cell is in hover range */
22
23
function inHoverRange ( cellStartRow : number , cellRowSpan : number , startRow : number , endRow : number ) {
@@ -120,19 +121,23 @@ function Cell<RecordType extends DefaultRecordType>(
120
121
) : React . ReactElement {
121
122
const cellPrefixCls = `${ prefixCls } -cell` ;
122
123
124
+ const perfRecord = React . useContext ( PerfContext ) ;
123
125
const supportSticky = React . useContext ( StickyContext ) ;
124
126
125
127
// ==================== Child Node ====================
126
- let cellProps : CellType < RecordType > ;
127
- let childNode : React . ReactNode ;
128
+ const [ childNode , legacyCellProps ] = React . useMemo <
129
+ [ React . ReactNode , CellType < RecordType > ] | [ React . ReactNode ]
130
+ > ( ( ) => {
131
+ if ( validateValue ( children ) ) {
132
+ return [ children ] ;
133
+ }
128
134
129
- if ( validateValue ( children ) ) {
130
- childNode = children ;
131
- } else {
132
135
const value = getPathValue < object | React . ReactNode , RecordType > ( record , dataIndex ) ;
133
136
134
137
// Customize render node
135
- childNode = value ;
138
+ let returnChildNode = value ;
139
+ let returnCellProps : CellType < RecordType > | undefined = undefined ;
140
+
136
141
if ( render ) {
137
142
const renderData = render ( value , record , renderIndex ) ;
138
143
@@ -143,25 +148,41 @@ function Cell<RecordType extends DefaultRecordType>(
143
148
'`columns.render` return cell props is deprecated with perf issue, please use `onCell` instead.' ,
144
149
) ;
145
150
}
146
- childNode = renderData . children ;
147
- cellProps = renderData . props ;
151
+ returnChildNode = renderData . children ;
152
+ returnCellProps = renderData . props ;
153
+ perfRecord . renderWithProps = true ;
148
154
} else {
149
- childNode = renderData ;
155
+ returnChildNode = renderData ;
150
156
}
151
157
}
152
- }
158
+
159
+ return [ returnChildNode , returnCellProps ] ;
160
+ } , [
161
+ /* eslint-disable react-hooks/exhaustive-deps */
162
+ // Always re-render if `renderWithProps`
163
+ perfRecord . renderWithProps ? Math . random ( ) : 0 ,
164
+ /* eslint-enable */
165
+ children ,
166
+ dataIndex ,
167
+ perfRecord ,
168
+ record ,
169
+ render ,
170
+ renderIndex ,
171
+ ] ) ;
172
+
173
+ let mergedChildNode = childNode ;
153
174
154
175
// Not crash if final `childNode` is not validate ReactNode
155
176
if (
156
- typeof childNode === 'object' &&
157
- ! Array . isArray ( childNode ) &&
158
- ! React . isValidElement ( childNode )
177
+ typeof mergedChildNode === 'object' &&
178
+ ! Array . isArray ( mergedChildNode ) &&
179
+ ! React . isValidElement ( mergedChildNode )
159
180
) {
160
- childNode = null ;
181
+ mergedChildNode = null ;
161
182
}
162
183
163
184
if ( ellipsis && ( lastFixLeft || firstFixRight ) ) {
164
- childNode = < span className = { `${ cellPrefixCls } -content` } > { childNode } </ span > ;
185
+ mergedChildNode = < span className = { `${ cellPrefixCls } -content` } > { mergedChildNode } </ span > ;
165
186
}
166
187
167
188
const {
@@ -170,7 +191,7 @@ function Cell<RecordType extends DefaultRecordType>(
170
191
style : cellStyle ,
171
192
className : cellClassName ,
172
193
...restCellProps
173
- } = cellProps || { } ;
194
+ } = legacyCellProps || { } ;
174
195
const mergedColSpan = ( cellColSpan !== undefined ? cellColSpan : colSpan ) ?? 1 ;
175
196
const mergedRowSpan = ( cellRowSpan !== undefined ? cellRowSpan : rowSpan ) ?? 1 ;
176
197
@@ -220,10 +241,13 @@ function Cell<RecordType extends DefaultRecordType>(
220
241
let title : string ;
221
242
const ellipsisConfig : CellEllipsisType = ellipsis === true ? { showTitle : true } : ellipsis ;
222
243
if ( ellipsisConfig && ( ellipsisConfig . showTitle || rowType === 'header' ) ) {
223
- if ( typeof childNode === 'string' || typeof childNode === 'number' ) {
224
- title = childNode . toString ( ) ;
225
- } else if ( React . isValidElement ( childNode ) && typeof childNode . props . children === 'string' ) {
226
- title = childNode . props . children ;
244
+ if ( typeof mergedChildNode === 'string' || typeof mergedChildNode === 'number' ) {
245
+ title = mergedChildNode . toString ( ) ;
246
+ } else if (
247
+ React . isValidElement ( mergedChildNode ) &&
248
+ typeof mergedChildNode . props . children === 'string'
249
+ ) {
250
+ title = mergedChildNode . props . children ;
227
251
}
228
252
}
229
253
@@ -248,7 +272,7 @@ function Cell<RecordType extends DefaultRecordType>(
248
272
[ `${ cellPrefixCls } -ellipsis` ] : ellipsis ,
249
273
[ `${ cellPrefixCls } -with-append` ] : appendNode ,
250
274
[ `${ cellPrefixCls } -fix-sticky` ] : ( isFixLeft || isFixRight ) && isSticky && supportSticky ,
251
- [ `${ cellPrefixCls } -row-hover` ] : ! cellProps && hovering ,
275
+ [ `${ cellPrefixCls } -row-hover` ] : ! legacyCellProps && hovering ,
252
276
} ,
253
277
additionalProps . className ,
254
278
cellClassName ,
@@ -262,7 +286,7 @@ function Cell<RecordType extends DefaultRecordType>(
262
286
return (
263
287
< Component { ...componentProps } >
264
288
{ appendNode }
265
- { childNode }
289
+ { mergedChildNode }
266
290
</ Component >
267
291
) ;
268
292
}
0 commit comments