Skip to content

🐛 修复拖拽组件导致触发focusin / focusout卡顿 #1224#1243

Merged
CodFrm merged 4 commits intorelease/v1.3from
fix/1224
Feb 14, 2026
Merged

🐛 修复拖拽组件导致触发focusin / focusout卡顿 #1224#1243
CodFrm merged 4 commits intorelease/v1.3from
fix/1224

Conversation

@CodFrm
Copy link
Member

@CodFrm CodFrm commented Feb 14, 2026

@cyfung1031
Copy link
Collaborator

我看看~

@cyfung1031
Copy link
Collaborator

cyfung1031 commented Feb 14, 2026

RFC 9239

以前出现过 application/javascript 这东西
但 2022 年又改回 text/javascript 了
估计日后都不会重提 application/javascript 这东西

// 当dragzone使用时,在<html>加入.dragzone-active,控制CSS行为
// 只改CSS,不要改动React元件的任何状态,否则会触发重绘计算
useEffect(() => {
document.documentElement.classList.toggle("dragzone-active", isDragActive);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放body/root div是不是更好

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

个人习惯 dark theme 什么的都放在 <html> ( 可以 .dragzone-active body )
页面一定有这个 element
你喜欢吧。都一样。写body的话字数少一点。写root的话要getElementById

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我都是放在body,没什么大问题,我修改一下

@CodFrm CodFrm merged commit 524a47c into release/v1.3 Feb 14, 2026
1 of 2 checks passed
@CodFrm CodFrm requested a review from Copilot February 14, 2026 10:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 修复了拖拽组件导致 focusin/focusout 事件触发卡顿的问题(issue #1224),并进行了相关的性能优化。

Changes:

  • 在 react-dropzone 配置中添加 noClick: truenoKeyboard: true 以避免不必要的焦点事件
  • 使用 CSS pointer-events: none 在拖拽激活时禁用内容区域的指针事件,防止 tooltip 等组件弹出
  • 提取 DropzoneOverlay 为独立的 memo 组件以优化重绘性能
  • 将工具函数(formatUrlsimpleDigestMessage)移出组件外部,避免每次渲染时重新定义
  • 使用 useMemo 缓存语言列表,减少不必要的计算
  • 将 MIME 类型从 application/javascript 统一改为 text/javascript

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pages/components/layout/index.css 添加 CSS 规则,在拖拽激活时禁用布局内容区域的指针事件
src/pages/components/layout/MainLayout.tsx 重构拖拽相关代码,添加性能优化,配置 dropzone 禁用键盘和点击事件,统一 MIME 类型

// 当dragzone使用时,在<body>加入.dragzone-active,控制CSS行为
// 只改CSS,不要改动React元件的任何状态,否则会触发重绘计算
useEffect(() => {
document.body.classList.toggle("dragzone-active", isDragActive);
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffect 缺少清理函数。当组件卸载时,应该移除 body 上的 'dragzone-active' 类,否则该类可能会在组件卸载后仍然保留在 body 上。建议添加返回的清理函数来移除该类。

Suggested change
document.body.classList.toggle("dragzone-active", isDragActive);
document.body.classList.toggle("dragzone-active", isDragActive);
return () => {
// 组件卸载时确保移除全局样式类,防止状态残留
document.body.classList.remove("dragzone-active");
};

Copilot uses AI. Check for mistakes.
Copy link
Member Author

@CodFrm CodFrm Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

错误的

@cyfung1031 cyfung1031 deleted the fix/1224 branch February 14, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants