Browse Source

fix(tooltip): fixed tooltip may setState when component is unmounted #727 (#731)

走鹃 3 years ago
parent
commit
17a00e06c0

+ 33 - 0
packages/semi-ui/table/_story/v2/FixedMemoryLeak/index.jsx

@@ -0,0 +1,33 @@
+import React, { useState } from 'react';
+import { Popconfirm, Table } from "@douyinfe/semi-ui";
+
+export default function App() {
+    const [data, setData] = useState([{ a: 1 }]);
+    return (
+        <Table
+            dataSource={data}
+            columns={[
+                {
+                    dataIndex: "a",
+                    title: "a",
+                },
+                {
+                    dataIndex: "b",
+                    render: () => {
+                        return (
+                            <Popconfirm
+                                onConfirm={() => {
+                                    setTimeout(() => {
+                                        setData([]);
+                                    });
+                                }}
+                            >
+                                删除
+                            </Popconfirm>
+                        );
+                    },
+                },
+            ]}
+        />
+    );
+}

+ 2 - 1
packages/semi-ui/table/_story/v2/index.js

@@ -3,4 +3,5 @@ export { default as FixedColumnsChange } from './FixedColumnsChange';
 export { default as FixedZIndex } from './FixedZIndex';
 export { default as FixedHeaderMerge } from './FixedHeaderMerge';
 export { default as FixedResizable } from './FixedResizable';
-export { default as FixedExpandedRow } from './FixedExpandedRow';
+export { default as FixedExpandedRow } from './FixedExpandedRow';
+export { default as FixedMemoryLeak  } from './FixedMemoryLeak';

+ 1 - 1
packages/semi-ui/tooltip/index.tsx

@@ -302,7 +302,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
                 } else {
                     willUpdateStates.visible = visible;
                 }
-                this.setState(willUpdateStates as TooltipState, () => {
+                this.mounted && this.setState(willUpdateStates as TooltipState, () => {
                     cb();
                 });
             },