From 773857848b368553a7a4008c41cbe8be552b6dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 9 Jan 2025 20:38:44 +0100 Subject: [PATCH] FIX: lockup when navigating with j/k (#30674) If, for some reasons, navigating between posts using j/k keyboard shortcuts does not select any posts, there could be an infinite loop due to setting the `direction` to `0` and then using it do "iterate" over the arrays of available "articles". Despite many attemps, I wasn't able to reproduce the issue reported in https://dev.discourse.org/t/145565 so this is somewhat of a shot in the dark. --- .../javascripts/discourse/app/lib/keyboard-shortcuts.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js index 1256dcc1467..f1cb8209e22 100644 --- a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js +++ b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js @@ -775,6 +775,11 @@ export default { if (article.getBoundingClientRect().height > 0) { break; } + + // Safeguard against infinite loops + if (direction === 0) { + break; + } } for (const a of articles) {