Skip to content

fix(previewer): ignore pending image callbacks after destroy - #1871

Merged
sunsonliu merged 1 commit into
Tencent:devfrom
dvd233:fix/lazy-image-callback-after-destroy
Sep 1, 2026
Merged

sunsonliu merged 1 commit into
Tencent:devfrom
dvd233:fix/lazy-image-callback-after-destroy

Conversation

@dvd233

@dvd233 dvd233 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

问题背景

LazyLoadImg.destroy() 会清理 options、预览 DOM 和加载状态,但已经发出的图片请求仍可能在稍后触发 load / error。原有异步闭包会继续访问已清理的 options,从而在编辑器销毁后抛出 TypeError。

Fixes #1868

修改内容

  • 在懒加载图片的成功与失败异步回调入口增加 isDestroyed 门禁
  • 销毁后不再修改图片 DOM、加载队列或触发业务回调
  • 增加参数化回归测试,覆盖迟到的 load 与 error 两条路径
  • 添加 cherry-markdown patch changeset

验证

  • yarn lint(0 errors;仅仓库既有 warnings)
  • yarn typecheck
  • yarn test(128 test files,2221 tests 全部通过)
  • yarn build
  • node node_modules/es-check/index.js es5 packages/cherry-markdown/dist/cherry-markdown.js
  • Chrome 浏览器验证:将图片响应延迟 500ms,在请求进行中销毁 Cherry;无 error / unhandledrejection,且加载成功/失败业务回调均未触发

本地环境说明

Windows 下执行 vp run -F cherry-markdown test:artifacts 时,7 项中 6 项通过;剩余 ES5 子检查将反斜杠绝对路径传给 fast-glob 后无法匹配文件。对同一构建产物使用仓库相对路径执行等价 es-check 已通过。该差异不涉及本次源代码行为。

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6891165

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
cherry-markdown Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tencent-adm

tencent-adm commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

@sunsonliu sunsonliu left a comment

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.

LGTM,感谢贡献~!

@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

cherry-markdown

pnpm add https://pkg.pr.new/cherry-markdown@1871
npm i https://pkg.pr.new/cherry-markdown@1871
yarn add https://pkg.pr.new/cherry-markdown@1871.tgz

@cherry-markdown/miniprogram

pnpm add https://pkg.pr.new/@cherry-markdown/miniprogram@1871
npm i https://pkg.pr.new/@cherry-markdown/miniprogram@1871
yarn add https://pkg.pr.new/@cherry-markdown/miniprogram@1871.tgz

commit: 6891165

@cherry-markdown-bot

Copy link
Copy Markdown
Collaborator

🔌 VSCode Plugin 构建产物

下载 .vsix

⏰ 产物保留 5 天

@cherry-markdown-bot

Copy link
Copy Markdown
Collaborator

💻 Client 构建产物

平台 架构 产物类型 下载
macOS Apple Silicon App 应用 下载
macOS Apple Silicon DMG 安装包 下载
macOS x64 App 应用 下载
macOS x64 DMG 安装包 下载
Windows x64 EXE 安装程序 下载
Windows x64 MSI 安装包 下载
Linux x64 Deb 包 下载
Linux x64 AppImage 下载

⏰ 产物保留 5 天

@sunsonliu
sunsonliu merged commit 11652f3 into Tencent:dev Sep 1, 2026
18 checks passed
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.

销毁组件时如果还有图片未加载完,会报 options is null 的 TypeError

4 participants