Deal with disconnected elems in mathml.isMathJaxIgnored
I didn't take into account we might get handed an element that's not attached to the body. closes LS-1715 flag=none test plan: - load /courses/:id/pages > expect no exception to be thrown from mathml.isMathJaxIgnored in particular: Uncaught TypeError: Cannot read property 'querySelector' of null or Uncaught TypeError: Cannot read property 'classList' of nul Change-Id: I079b57521574b5ce7a3ed11ced4a985d47762e04 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/255380 Reviewed-by: Jeff Largent <jeff.largent@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Robin Kuss <rkuss@instructure.com> Product-Review: Ed Schiebel <eschiebel@instructure.com>
This commit is contained in:
parent
fe1c775007
commit
ae400db192
|
@ -143,12 +143,17 @@ const mathml = {
|
|||
},
|
||||
|
||||
isMathJaxIgnored(elem) {
|
||||
if (!elem) return true
|
||||
|
||||
// ignore disconnected elements
|
||||
if (!document.body.contains(elem)) return true
|
||||
|
||||
// elements to ignore selector
|
||||
const ignore_list =
|
||||
'.MJX_Assistive_MathML,#header,#mobile-header,#left-side,#quiz-elapsed-time,.ui-menu-carat'
|
||||
|
||||
// check if elem is in the ignore list
|
||||
if (elem.parentElement.querySelector(ignore_list) === elem) {
|
||||
if (elem.parentElement?.querySelector(ignore_list) === elem) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -314,3 +314,13 @@ test('ignores descendents of .mathjax_ignore', () => {
|
|||
ignored.appendChild(elem)
|
||||
ok(mathml.isMathJaxIgnored(elem))
|
||||
})
|
||||
|
||||
test('deals with disconnected elements', () => {
|
||||
// even though they should never get here
|
||||
const elem = document.createElement('span')
|
||||
ok(mathml.isMathJaxIgnored(elem))
|
||||
})
|
||||
|
||||
test('handles missing element', () => {
|
||||
ok(mathml.isMathJaxIgnored())
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue