Skip to content

fix: prevent file processing crash and duplicate on long text paste#315

Open
chengcheng84 wants to merge 4 commits intoCherryHQ:mainfrom
chengcheng84:fix/long-text-crash
Open

fix: prevent file processing crash and duplicate on long text paste#315
chengcheng84 wants to merge 4 commits intoCherryHQ:mainfrom
chengcheng84:fix/long-text-crash

Conversation

@chengcheng84
Copy link
Copy Markdown
Contributor

@chengcheng84 chengcheng84 commented Feb 17, 2026

Fix #314 #235

修复之后发现,文本会被粘贴为2个文件

Add ref to track processing state and skip duplicate processing of the same text input
@eeee0717
Copy link
Copy Markdown
Collaborator

Potential race in processingTextRef: each async setText call always clears the ref in finally. If long text A starts, then long text B starts, A can finish first and set the ref to null while B is still processing. A subsequent setText(B) bypasses dedupe and may trigger duplicate conversion/file creation. Suggestion: only clear when processingTextRef.current === newText (or use a monotonic request id).

} else {
// Fallback on error - keep the text
setTextInternal(newText)
} finally {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

可按下面方式修复,避免旧请求把新请求的 guard 清掉:

} finally {
  if (processingTextRef.current === newText) {
    processingTextRef.current = null
  }
}

这样在 AB 并发时,只有仍持有当前 guard 的那次调用才会清空,setText(B) 不会在 B 处理中被误放行。

@chengcheng84 chengcheng84 requested a review from eeee0717 March 2, 2026 14:39
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.

[Bug]: 长文本粘贴时崩溃

2 participants