Skip to content

Commit

Permalink
Merge pull request #1058 from alleyinteractive/issue-1030
Browse files Browse the repository at this point in the history
Prevent error by adding check before displaying notices
  • Loading branch information
attackant authored Jan 31, 2024
2 parents 2fec435 + c77b081 commit cb7a18e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion assets/js/pluginsidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ function Sidebar() {

// Display notices whenever they change.
useEffect(() => {
notices.forEach((notice) => displayNotification(notice.message, notice.type));
/* Adding a conditional here to prevent a sporadic error.
Leaving a console log in place in case we need to debug this further.
See: https://github.com/alleyinteractive/apple-news/issues/1030 */
if (Array.isArray(notices) && notices.length) {
notices.forEach((notice) => displayNotification(notice.message, notice.type));
} else {
console.log('Notices dispatched, but none to display.'); // eslint-disable-line no-console
}
}, [displayNotification, notices]);

return (
Expand Down

0 comments on commit cb7a18e

Please sign in to comment.