From 2e00b2f0bb7222998c04cb5b85dded8a198de583 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 27 Feb 2026 23:23:21 +0100 Subject: [PATCH] Fix `no-content` message not rendering after comment edit (#36733) When non-empty comment content edited is deleted, it would render a empty comment body: image Fix it so it renders the same placeholder HTML that the server sends for empty content before edits: image --- routers/web/repo/issue.go | 10 +++++++++- routers/web/repo/issue_comment.go | 8 +------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index eaec3b5789..a295a3c903 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -21,6 +21,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/htmlutil" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/optional" @@ -369,7 +370,7 @@ func UpdateIssueContent(ctx *context.Context) { } ctx.JSON(http.StatusOK, map[string]any{ - "content": content, + "content": commentContentHTML(ctx, content), "contentVersion": issue.ContentVersion, "attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content), }) @@ -629,6 +630,13 @@ func updateAttachments(ctx *context.Context, item any, files []string) error { return err } +func commentContentHTML(ctx *context.Context, content template.HTML) template.HTML { + if strings.TrimSpace(string(content)) == "" { + return htmlutil.HTMLFormat(`%s`, ctx.Tr("repo.issues.no_content")) + } + return content +} + func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment, content string) template.HTML { attachHTML, err := ctx.RenderToHTML(tplAttachment, map[string]any{ "ctxData": ctx.Data, diff --git a/routers/web/repo/issue_comment.go b/routers/web/repo/issue_comment.go index a3cb88e76a..7f8cc23a3f 100644 --- a/routers/web/repo/issue_comment.go +++ b/routers/web/repo/issue_comment.go @@ -9,7 +9,6 @@ import ( "html/template" "net/http" "strconv" - "strings" git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" @@ -17,7 +16,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" - "code.gitea.io/gitea/modules/htmlutil" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" repo_module "code.gitea.io/gitea/modules/repository" @@ -291,12 +289,8 @@ func UpdateCommentContent(ctx *context.Context) { } } - if strings.TrimSpace(string(renderedContent)) == "" { - renderedContent = htmlutil.HTMLFormat(`%s`, ctx.Tr("repo.issues.no_content")) - } - ctx.JSON(http.StatusOK, map[string]any{ - "content": renderedContent, + "content": commentContentHTML(ctx, renderedContent), "contentVersion": comment.ContentVersion, "attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content), })