Skip to content

Commit 6f6227b

Browse files
authored
fix: not crash on components (#838)
1 parent 0991231 commit 6f6227b

File tree

3 files changed

+19
-45
lines changed

3 files changed

+19
-45
lines changed

src/Table.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import BodyContext from './context/BodyContext';
6161
import Body from './Body';
6262
import useColumns from './hooks/useColumns';
6363
import { useLayoutState, useTimeoutLock } from './hooks/useFrame';
64-
import { getPathValue, mergeObject, validateValue, getColumnsKey } from './utils/valueUtil';
64+
import { getPathValue, validateValue, getColumnsKey } from './utils/valueUtil';
6565
import ResizeContext from './context/ResizeContext';
6666
import useStickyOffsets from './hooks/useStickyOffsets';
6767
import ColGroup from './ColGroup';
@@ -226,16 +226,11 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
226226
}
227227

228228
// ==================== Customize =====================
229-
const mergedComponents = React.useMemo(
230-
() => mergeObject<TableComponents<RecordType>>(components, {}),
231-
[components],
232-
);
233-
234229
const getComponent = React.useCallback<GetComponent>(
235230
(path, defaultComponent) =>
236-
getPathValue<CustomizeComponent, TableComponents<RecordType>>(mergedComponents, path) ||
231+
getPathValue<CustomizeComponent, TableComponents<RecordType>>(components || {}, path) ||
237232
defaultComponent,
238-
[mergedComponents],
233+
[components],
239234
);
240235

241236
const getRowKey = React.useMemo<GetRowKey<RecordType>>(() => {
@@ -811,15 +806,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
811806
),
812807
isSticky,
813808
}),
814-
[
815-
prefixCls,
816-
getComponent,
817-
scrollbarSize,
818-
direction,
819-
flattenColumns,
820-
stickyOffsets,
821-
isSticky,
822-
],
809+
[prefixCls, getComponent, scrollbarSize, direction, flattenColumns, stickyOffsets, isSticky],
823810
);
824811

825812
const BodyContextValue = React.useMemo(

src/utils/valueUtil.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,6 @@ export function getColumnsKey(columns: readonly GetColumnKeyColumn[]) {
5858
return columnKeys;
5959
}
6060

61-
export function mergeObject<ReturnObject extends object>(
62-
...objects: Partial<ReturnObject>[]
63-
): ReturnObject {
64-
const merged: Partial<ReturnObject> = {};
65-
66-
/* eslint-disable no-param-reassign */
67-
function fillProps(obj: object, clone: object) {
68-
if (clone) {
69-
Object.keys(clone).forEach(key => {
70-
const value = clone[key];
71-
if (value && typeof value === 'object') {
72-
obj[key] = obj[key] || {};
73-
fillProps(obj[key], value);
74-
} else {
75-
obj[key] = value;
76-
}
77-
});
78-
}
79-
}
80-
/* eslint-enable */
81-
82-
objects.forEach(clone => {
83-
fillProps(merged, clone);
84-
});
85-
86-
return merged as ReturnObject;
87-
}
88-
8961
export function validateValue<T>(val: T) {
9062
return val !== null && val !== undefined;
9163
}

tests/Table.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,21 @@ describe('Table.Basic', () => {
596596
errSpy.mockRestore();
597597
});
598598
});
599+
600+
it('not crash', () => {
601+
const Looper = React.forwardRef(() => <td />);
602+
Looper.looper = Looper;
603+
604+
mount(
605+
createTable({
606+
components: {
607+
body: {
608+
cell: Looper,
609+
},
610+
},
611+
}),
612+
);
613+
});
599614
});
600615

601616
it('align column', () => {

0 commit comments

Comments
 (0)