FIX: Redirect to homepage if no posts exist (#14951)

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.

diff --git a/app/assets/javascripts/discourse/app/widgets/post-stream.js b/app/assets/javascripts/discourse/app/widgets/post-stream.js
index 7d2c8af..69d532b 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 : {};

GitHub sha: 88523a6d6a65255a3bfd5157b33d848acbd0cd86

This commit appears in #14951 which was approved by eviltrout. It was merged by nbianca.