moodle/moodle · error
Inexistent overlay element
Error message
Inexistent overlay element
What it means
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.
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.
Example fix
// before: repositioning with a possibly stale element
window.addEventListener('resize', () => rePosition(overlayElement));
// after: verify the element is still in the DOM
window.addEventListener('resize', () => {
if (overlayElement && overlayElement.isConnected) {
rePosition(overlayElement);
}
}); Defensive patterns
Strategy: validation
Validate before calling
const overlay = document.querySelector('#my-overlay');
if (!overlay || !overlay.isConnected) {
return; // skip repositioning
} Prevention
- Re-fetch overlay elements after any DOM re-render.
- Guard scroll/resize handlers with element.isConnected checks.
- Verify selectors resolve before calling overlay APIs.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Dopdown status element not found
- Draggable components must have a getDraggableData method
- Missing watch attribute in
- Reactivity event required
- A contextlist has already been added for the
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/82a4a52f7cb458a3.
Report an issue: GitHub.
Appendix: source
Thrown at public/lib/amd/src/local/reactive/overlay.js:109
overlay.parentNode.removeChild(overlay);
};
export const removeAllOverlays = () => {
document.querySelectorAll(selectors.OVERLAY).forEach(
(overlay) => {
removeOverlay(overlay);
}
);
};
/**
* Re-position the preview information element by calculating the section position.
*
* @param {Object} overlay the overlay element.
*/
const rePositionPreviewInfoElement = function(overlay) {
if (!overlay) {
throw new Error('Inexistent overlay element');
}
// Add relative position to the parent object.
if (!overlay.parentNode?.style?.position) {
overlay.parentNode.style.position = 'relative';
overlay.dataset.overlayPosition = "true";
}
// Get the element to reposition.
const target = overlay.querySelector(selectors.REPOSITION);
if (!target) {
return;
}
// Get the new bounds.
const rect = overlay.getBoundingClientRect();
const sectionHeight = parseInt(window.getComputedStyle(overlay).height, 10);
const sectionOffset = rect.top;
const previewHeight = parseInt(window.getComputedStyle(target).height, 10) +
(2 * parseInt(window.getComputedStyle(target).padding, 10));
// Calculate the new target position.View on GitHub (pinned to 48ea8c3322)