Skip to content

Commit

Permalink
fix(Table): 处理 Column.formatter 返回循环依赖对象的情况 (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zumii committed May 15, 2024
1 parent 122ebe8 commit cdf3b40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 11 additions & 0 deletions components/_util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,14 @@ export function concat(arr: any[], arr2: any[]) {
}
return arr;
}

// JSON.stringify
export function stringify(value: any, onError?: (err: unknown) => void, fallbackValue: string = ''): string {
try {
const str = JSON.stringify(value);
return str;
} catch (err) {
onError?.(err);
return fallbackValue;
}
}
14 changes: 9 additions & 5 deletions components/table/components/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { provideKey } from '../const';

import type { ActionType } from '../interface';
import type { ColumnInst } from '../column';
import { stringify } from '../../_util/utils';

const cellProps = {
row: {
Expand All @@ -40,8 +41,10 @@ const cellProps = {

export type InnerCellProps = ExtractPropTypes<typeof cellProps>;

const COMPONENT_NAME = 'FTableCell';

export default defineComponent({
name: 'FTableCell',
name: COMPONENT_NAME,
props: cellProps,
setup(props) {
const { prefixCls } = inject(provideKey);
Expand Down Expand Up @@ -102,13 +105,14 @@ export default defineComponent({
const result = formatterResult ?? cellValue;
Object.assign(ellipsisProps, { content: result });
return hasEllipsis
? (
<Ellipsis {...ellipsisProps}></Ellipsis>
)
? <Ellipsis {...ellipsisProps} />
: (
<Fragment>
{typeof result === 'object'
? JSON.stringify(result)
? stringify(
result,
(err) => console.warn(`[${COMPONENT_NAME}]: render error occurred due to \n`, err),
)
: result}
</Fragment>
);
Expand Down

0 comments on commit cdf3b40

Please sign in to comment.