From 88523a6d6a65255a3bfd5157b33d848acbd0cd86 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 16 Nov 2021 11:10:07 +0200 Subject: [PATCH] FIX: Redirect to homepage if no posts exist (#14951) After permanently deleting the first post of a topic the user was sometimes stuck on the page because of an infinite loop. This problem happened more often in Firefox. --- app/assets/javascripts/discourse/app/widgets/post-stream.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/widgets/post-stream.js b/app/assets/javascripts/discourse/app/widgets/post-stream.js index 7d2c8afc750..69d532b1456 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-stream.js +++ b/app/assets/javascripts/discourse/app/widgets/post-stream.js @@ -189,7 +189,8 @@ export default createWidget("post-stream", { const posts = attrs.posts || []; const postArray = posts.toArray(); const postArrayLength = postArray.length; - const maxPostNumber = postArray[postArrayLength - 1].post_number; + const maxPostNumber = + postArrayLength > 0 ? postArray[postArrayLength - 1].post_number : 0; const result = []; const before = attrs.gaps && attrs.gaps.before ? attrs.gaps.before : {}; const after = attrs.gaps && attrs.gaps.after ? attrs.gaps.after : {};