handle getElementById failures in articlePage (#16743)
* when there is no div for it, don't render CommentSubscription * Retrigger CI * Retrigger CI * don't write an error to the comment div if its gone This fixes an issue seen in tests, where the page transitioned while we were running the articlePage async handler, so the article-body element was gone (can't access dataset of null), and the error handler catch block tried to access the innerHTML of another getElementById. * Use existing found element `root` when setting the error message No need to find a new comment-subscription div to write the error to, we already named the one we're interested in at the beginning of the function
This commit is contained in:
parent
6cc341e70e
commit
c5a90173bd
1 changed files with 4 additions and 1 deletions
|
|
@ -90,6 +90,9 @@ getCsrfToken().then(async () => {
|
|||
const root = document.getElementById('comment-subscription');
|
||||
const isLoggedIn = userStatus === 'logged-in';
|
||||
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const {
|
||||
getCommentSubscriptionStatus,
|
||||
|
|
@ -124,7 +127,7 @@ getCsrfToken().then(async () => {
|
|||
root,
|
||||
);
|
||||
} catch (e) {
|
||||
document.getElementById('comment-subscription').innerHTML =
|
||||
root.innerHTML =
|
||||
'<p className="color-accent-danger">Unable to load Comment Subscription component.<br />Try refreshing the page.</p>';
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue