{"record":{"id":"82a4a52f7cb458a3","repo":"moodle/moodle","slug":"inexistent-overlay-element","errorCode":null,"errorMessage":"Inexistent overlay element","messagePattern":"Inexistent overlay element","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"public/lib/amd/src/local/reactive/overlay.js","lineNumber":109,"sourceCode":"    overlay.parentNode.removeChild(overlay);\n};\n\nexport const removeAllOverlays = () => {\n    document.querySelectorAll(selectors.OVERLAY).forEach(\n        (overlay) => {\n            removeOverlay(overlay);\n        }\n    );\n};\n\n/**\n * Re-position the preview information element by calculating the section position.\n *\n * @param {Object} overlay the overlay element.\n */\nconst rePositionPreviewInfoElement = function(overlay) {\n    if (!overlay) {\n        throw new Error('Inexistent overlay element');\n    }\n    // Add relative position to the parent object.\n    if (!overlay.parentNode?.style?.position) {\n        overlay.parentNode.style.position = 'relative';\n        overlay.dataset.overlayPosition = \"true\";\n    }\n    // Get the element to reposition.\n    const target = overlay.querySelector(selectors.REPOSITION);\n    if (!target) {\n        return;\n    }\n    // Get the new bounds.\n    const rect = overlay.getBoundingClientRect();\n    const sectionHeight = parseInt(window.getComputedStyle(overlay).height, 10);\n    const sectionOffset = rect.top;\n    const previewHeight = parseInt(window.getComputedStyle(target).height, 10) +\n        (2 * parseInt(window.getComputedStyle(target).padding, 10));\n    // Calculate the new target position.","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/amd/src/local/reactive/overlay.js#L91-L127","documentation":"The reactive overlay module's rePositionPreviewInfoElement() expects the overlay DOM element to have been created/registered before repositioning is attempted. A null/undefined overlay argument means the library would try to read overlay.parentNode and dataset, which would crash confusingly, so it throws an explicit 'Inexistent overlay element' error. It is raised from addOverlay() and init() when the overlay element could not be resolved.","triggerScenarios":"Calling addOverlay()/init() with a selector or element that resolved to null; the overlay element having been removed from the DOM (e.g. content re-rendered) before a reposition happens on scroll/resize; passing the wrong variable (undefined) into the internal reposition path.","commonSituations":"Base theme or course-format JS removing/replacing DOM nodes so the cached overlay element detaches; calling the overlay API before the page finished loading; a selector typo so no overlay element is found; interacting with overlay after a section/course editor re-render wiped it.","solutions":["Ensure addOverlay()/init() is called with a valid, existing element or selector — check document.querySelector returns non-null before calling.","Re-create/re-fetch the overlay element after any DOM re-render instead of reusing a stale reference.","Guard the repositioning path: only trigger reposition on scroll/resize when the overlay is still connected (overlay.isConnected).","Fix selector typos and confirm the target element is inside the document at call time."],"exampleFix":"// before: repositioning with a possibly stale element\nwindow.addEventListener('resize', () => rePosition(overlayElement));\n\n// after: verify the element is still in the DOM\nwindow.addEventListener('resize', () => {\n    if (overlayElement && overlayElement.isConnected) {\n        rePosition(overlayElement);\n    }\n});","handlingStrategy":"validation","validationCode":"const overlay = document.querySelector('#my-overlay');\nif (!overlay || !overlay.isConnected) {\n    return; // skip repositioning\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-fetch overlay elements after any DOM re-render.","Guard scroll/resize handlers with element.isConnected checks.","Verify selectors resolve before calling overlay APIs."],"tags":["dom","overlay","reactive","moodle","null-element"],"backgroundTag":"null-argument","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}