{"record":{"id":"672499ce7b47c94c","repo":"krahets/hello-algo","slug":"starfield-no-origin-element-found","errorCode":null,"errorMessage":"Starfield: No origin element found.","messagePattern":"Starfield: No origin element found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"overrides/javascripts/starfield.js","lineNumber":117,"sourceCode":"    canvas.height = height;\n\n    canvas.style.position = \"absolute\";\n    canvas.style.top = \"0\";\n    canvas.style.left = \"0\";\n    canvas.style.width = \"100%\";\n    canvas.style.height = \"100%\";\n    canvas.style.zIndex = \"-1\";\n    canvasRGB = parseRGBA(config.canvasColor);\n\n    container.appendChild(canvas);\n\n    ctx = canvas.getContext(\"2d\");\n\n    if (config.auto) {\n      origin =\n        config.originElement || document.querySelector(\".starfield-origin\");\n      if (!origin) {\n        throw new Error(\"Starfield: No origin element found.\");\n      }\n      originX = getOriginX(origin, container);\n      originY = getOriginY(origin, container);\n\n      origin.addEventListener(\"mouseenter\", mouseEnterHandler);\n      origin.addEventListener(\"mouseleave\", mouseLeaveHandler);\n\n      window.addEventListener(\"resize\", resizeHandler);\n    } else {\n      originX = config.originX !== null ? config.originX : width / 2;\n      originY = config.originY !== null ? config.originY : height / 2;\n    }\n\n    for (let i = 0; i < config.numStars; i++) {\n      const star = createRandomStar();\n      stars.push(star);\n    }\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/overrides/javascripts/starfield.js#L99-L135","documentation":"Thrown by setup() in the starfield module only when `config.auto` is truthy. In auto mode an origin element is required (the point stars emanate from); it is taken from `config.originElement` or `document.querySelector('.starfield-origin')`. If neither resolves, setup aborts before binding mouse handlers.","triggerScenarios":"Calling setup({ auto: true }) on a page lacking any `.starfield-origin` element and without `originElement` in config; auto mode enabled in theme config but the corresponding origin markup is conditional and absent; origin element removed by an SPA route change before setup; selector typo.","commonSituations":"MkDocs/Material override where the origin element is only rendered on certain pages (e.g. the home/hero section); enabling `auto` globally but some pages omit the hero; deferred script racing the DOM; CSS class renamed without updating the JS config.","solutions":["Add an element with class `starfield-origin` where you want stars to emanate, or pass `{ originElement: myEl }`.","If you do not need mouse-interactive origin, call setup without `auto: true` (it falls back to originX/originY or canvas center).","Confirm the origin element is present at setup time (DOMContentLoaded / after SPA render).","Double-check the `.starfield-origin` class spelling in the template."],"exampleFix":"// before\nstarfield.setup({ auto: true });\n\n// after\nconst origin = document.querySelector('.starfield-origin');\nif (origin) starfield.setup({ auto: true, originElement: origin });\nelse starfield.setup({ auto: false }); // or supply originX/originY","handlingStrategy":"validation","validationCode":"// In auto mode, ensure an origin element exists before setup.\nconst origin = document.querySelector('.starfield-origin');\nif (origin) {\n  starfield.setup({ auto: true, originElement: origin });\n} else {\n  starfield.setup({ auto: false }); // or pass originX/originY\n}","typeGuard":"function starfieldOriginReady(config) {\n  if (!config || !config.auto) return true;\n  const el = config.originElement || document.querySelector('.starfield-origin');\n  return el instanceof HTMLElement;\n}","tryCatchPattern":"try {\n  starfield.setup(userConfig);\n} catch (e) {\n  if (e instanceof Error && /No origin element found/.test(e.message)) {\n    // fall back to non-auto mode\n    starfield.setup({ ...userConfig, auto: false });\n  } else throw e;\n}","preventionTips":["Only enable `auto: true` on pages that render `.starfield-origin`.","Pass `originElement` explicitly to avoid relying on the global selector.","If the hero/origin section is conditional, gate `auto` on its presence.","In SPAs, re-check the origin element on each route change."],"tags":["starfield","dom","missing-element","config","javascript"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}