Skip to content

Commit b4513f4

Browse files
authored
Do not render empty comments (#29039)
Follow #28654 The `comments` might be empty, so the templates shouldn't (and couldn't) use it to render. When there is no comment, the UI should also be updated to empty, so returning an empty body is good enough.
1 parent 9bea276 commit b4513f4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

routers/web/repo/pull_review.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,19 @@ func UpdateResolveConversation(ctx *context.Context) {
153153
}
154154

155155
func renderConversation(ctx *context.Context, comment *issues_model.Comment, origin string) {
156+
ctx.Data["PageIsPullFiles"] = origin == "diff"
157+
156158
comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool))
157159
if err != nil {
158160
ctx.ServerError("FetchCodeCommentsByLine", err)
159161
return
160162
}
161-
ctx.Data["PageIsPullFiles"] = (origin == "diff")
163+
if len(comments) == 0 {
164+
// if the comments are empty (deleted, outdated, etc), it doesn't need to render anything, just return an empty body to replace "conversation-holder" on the page
165+
ctx.Resp.WriteHeader(http.StatusOK)
166+
return
167+
}
168+
162169
ctx.Data["comments"] = comments
163170
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, comment.Issue, ctx.Doer); err != nil {
164171
ctx.ServerError("CanMarkConversation", err)
@@ -179,6 +186,8 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
179186
ctx.HTML(http.StatusOK, tplDiffConversation)
180187
} else if origin == "timeline" {
181188
ctx.HTML(http.StatusOK, tplTimelineConversation)
189+
} else {
190+
ctx.Error(http.StatusBadRequest, "Unknown origin: "+origin)
182191
}
183192
}
184193

0 commit comments

Comments
 (0)