Skip to content

Commit

Permalink
fix(components): 修复 Popup 组件的报错问题
Browse files Browse the repository at this point in the history
- 引入 lodash 的 once 函数,确保弹窗关闭及卸载逻辑只执行一次
  • Loading branch information
neooier committed Jan 29, 2025
1 parent 70b2aaa commit 4347951
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { createRoot } from "react-dom/client";
import { MouseLocation } from "../core/service/controlService/MouseLocation";
import { cn } from "../utils/cn";
import once from "lodash/once";
import Box from "./Box";

export namespace Popup {
Expand All @@ -17,10 +18,13 @@ export namespace Popup {
y={MouseLocation.y}
onClose={() => {
resolve();
setTimeout(() => {
root.unmount();
document.body.removeChild(container);
}, 300);
setTimeout(
once(() => {
root.unmount();
document.body.removeChild(container);
}),
300,
);
}}
>
{children}
Expand Down

0 comments on commit 4347951

Please sign in to comment.