From 98523b2bd31688b0f4b637dc68ffeafea8bea563 Mon Sep 17 00:00:00 2001 From: Takagi <1103069291@qq.com> Date: Tue, 5 Mar 2024 15:20:09 +0800 Subject: [PATCH] fix: error editing post when img component has file attribute (#5434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area editor /area ui /milestone 2.14.x #### What this PR does / why we need it: 使用默认编辑器时,当图片、视频中具有 `file` 属性时,进入编辑界面时会报错。此 PR 将不再从渲染后的 HTML 中获取 file 属性,并且在渲染 HTML 时,抛弃掉 file 属性用于解决这个问题。 #### How to test it? 测试图片上传、视频上传功能不受影响即可。 #### Which issue(s) this PR fixes: Fixes #5430 #### Does this PR introduce a user-facing change? ```release-note 修复进入文章页面会偶现错误提示的问题 ``` --- ui/src/components/editor/extensions/image/index.ts | 12 +++++++++--- ui/src/components/editor/extensions/video/index.ts | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/src/components/editor/extensions/image/index.ts b/ui/src/components/editor/extensions/image/index.ts index 375223c46..2791e037f 100644 --- a/ui/src/components/editor/extensions/image/index.ts +++ b/ui/src/components/editor/extensions/image/index.ts @@ -22,9 +22,6 @@ const Image = ExtensionImage.extend({ addAttributes() { return { ...this.parent?.(), - file: { - default: null, - }, width: { default: "100%", parseHTML: (element) => { @@ -51,6 +48,15 @@ const Image = ExtensionImage.extend({ }; }, }, + file: { + default: null, + renderHTML() { + return {}; + }, + parseHTML() { + return null; + }, + }, }; }, diff --git a/ui/src/components/editor/extensions/video/index.ts b/ui/src/components/editor/extensions/video/index.ts index 44cac2e3e..c72fa2387 100644 --- a/ui/src/components/editor/extensions/video/index.ts +++ b/ui/src/components/editor/extensions/video/index.ts @@ -24,6 +24,12 @@ const Video = ExtensionVideo.extend({ ...this.parent?.(), file: { default: null, + renderHTML() { + return {}; + }, + parseHTML() { + return null; + }, }, }; },