Skip to content

Commit

Permalink
MDL-76694 core_comment: exit the js init if the element cannot be found
Browse files Browse the repository at this point in the history
In pages which result in the theme_boost/embedded template being used,
blocks may be rendered and the resulting HTML ignored, leaving any JS
they may have added to run without a corresponding DOM element to act
on. This fixes that case for comments, making sure we exit gracefully
during the init if the element can't be found.
  • Loading branch information
snake committed Nov 3, 2023
1 parent be7a698 commit 501c587
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ M.core_comment = {
this.courseid = args.courseid;
this.contextid = args.contextid;
this.autostart = (args.autostart);
// Fail fast if the comments element cannot be found, such as in embedded-type views where blocks may be loaded
// then discarded.
if (!Y.one('#comment-ctrl-'+this.client_id)) {
return;
}
// expand comments?
if (this.autostart) {
this.view(args.page);
Expand Down

0 comments on commit 501c587

Please sign in to comment.