Skip to content

fix(vue): ensure onFocus/onBlur/onAssetUpload callbacks use latest reference#125

Open
zhiyun22 wants to merge 1 commit into
floatboatai:mainfrom
zhiyun22:fix/vue-callback-reference-staleness
Open

fix(vue): ensure onFocus/onBlur/onAssetUpload callbacks use latest reference#125
zhiyun22 wants to merge 1 commit into
floatboatai:mainfrom
zhiyun22:fix/vue-callback-reference-staleness

Conversation

@zhiyun22

@zhiyun22 zhiyun22 commented Jul 3, 2026

Copy link
Copy Markdown

Summary / 摘要

修复 Vue 包中 onFocus、onBlur、onAssetUpload 回调引用过时的问题,确保回调在配置变化后始终调用最新版本。

Motivation / 背景与动机

  • Issue:
  • Roadmap (docs/ROADMAP.md):
  • OpenSpec change: fix-vue-callback-staleness

问题描述

packages/vueuseEditor 中,onChange 回调通过闭包 + resolveConfig() 动态获取最新引用,行为正确;但 onFocusonBluronAssetUpload 通过 ...rest 直接传给 createEditor,在编辑器创建时被固定引用。当配置是响应式的(computed / getter)且回调引用变化时,这些回调仍使用创建时的旧版本,可能导致:

  • 回调中访问到过期的闭包变量
  • 与 onChange 行为不一致
  • 依赖最新状态的场景下出现逻辑错误

Changes / 变更内容

  • packages/vue:
    • use-editor.ts: 将 buildCreateConfig 移入 useEditor 作用域,为 onFocusonBluronAssetUpload 创建包装函数,每次调用时通过 resolveConfig() 获取最新回调
    • editor-vue.test.ts: 新增 3 个测试用例,验证三个回调在配置更新后能调用最新版本

Testing / 测试

  • pnpm test passes / 全绿
  • Affected packages build (pnpm build) / 受影响包构建通过
  • New / updated vitest cases / 新增或更新的 vitest 用例:
    • calls the latest onFocus after config updates
    • calls the latest onBlur after config updates
    • calls the latest onAssetUpload after config updates
  • Manual UI check in electron-demo / electron-demo 手动验证:

测试命令

pnpm vitest run packages/vue

结果:18 tests passed(原有 15 个 + 新增 3 个)

Compliance / 合规自检

  • CLA signed — first-time contributors will be prompted automatically by the CLA bot / 首次贡献者按 CLA 机器人提示签署
  • AI disclosure: the functional code in this PR is not primarily generated by AI. AI assistance, if any, is described below.
    AI-assisted notes / AI 使用说明:
    AI-assisted code review and test case generation
  • New dependencies (if any) listed with license & rationale (none if blank):

    无新增依赖
  • No build artifacts committed (dist/, dist-electron/, compiled .js from .ts) / 未提交构建产物
  • No secrets / .env / personal vault data committed / 无敏感信息

Checklist / 自检清单

  • Title follows Conventional Commits / 标题遵循 Conventional Commits
  • Public API changes update package README / types — 改了公共 API 已同步 README 与类型(无公共 API 变更)
  • Touched live-preview-table.ts → walked through the 12 Table Widget rules in CLAUDE.md / 已核对 12 条表格规则(未涉及)
  • New capability / breaking change → OpenSpec proposal linked / 新 capability 或破坏性变更已附 OpenSpec(bug fix,不需要 OpenSpec)
  • Change aligns with project scope (GOVERNANCE.md §4) / 改动符合 GOVERNANCE.md §4 的项目范围

Screenshots / Recordings · 截图或录屏 (UI changes)

@CLAassistant

CLAassistant commented Jul 3, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@zhiyun22 zhiyun22 force-pushed the fix/vue-callback-reference-staleness branch from f919e4b to 615904c Compare July 6, 2026 02:55
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