{"record":{"id":"873dae295bd608f5","repo":"krahets/hello-algo","slug":"starfield-no-container-element-found","errorCode":null,"errorMessage":"Starfield: No container element found.","messagePattern":"Starfield: No container element found\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"overrides/javascripts/starfield.js","lineNumber":90,"sourceCode":"    return originRect.top - containerRect.top + originRect.height / 2;\n  }\n\n  function getOriginX(origin, container) {\n    const originRect = origin.getBoundingClientRect();\n    const containerRect = container.getBoundingClientRect();\n    return originRect.left - containerRect.left + originRect.width / 2;\n  }\n\n  /**\n   * Set up and start the starfield animation.\n   * @param {Object} userConfig Configuration options.\n   */\n  function setup(userConfig = {}) {\n    Object.assign(config, userConfig);\n\n    container = config.container || document.querySelector(\".starfield\");\n    if (!container) {\n      throw new Error(\"Starfield: No container element found.\");\n    }\n    // container.style.position = \"relative\";\n\n    width = container.clientWidth;\n    height = container.clientHeight;\n\n    canvas = document.createElement(\"canvas\");\n    canvas.width = width;\n    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","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/overrides/javascripts/starfield.js#L72-L108","documentation":"Thrown by setup() in the starfield animation module when no container element can be resolved. The container is taken from `config.container` if provided, otherwise from `document.querySelector('.starfield')`. If neither yields an element, setup aborts with this Error before any canvas is created.","triggerScenarios":"Calling starfield.setup() on a page that has no element with class `starfield` and no `container` in the config; calling setup before the DOM is ready (script ran in <head> without defer); CSS class typo so the selector misses; the container was removed/replaced after a SPA route change.","commonSituations":"MkDocs/Material theme where the starfield is an override: the `.starfield` block is conditional on a config flag and is absent; bundler or build strips the element; SPA navigation tears down the node before setup runs; running setup twice after the first instance consumed the node.","solutions":["Ensure an element with class `starfield` exists in the DOM before calling setup, or pass `{ container: myEl }` explicitly.","Defer setup until after DOMContentLoaded (or place the script at end of body / use `defer`).","In SPAs, re-query the container on each route change and pass it explicitly.","Verify the override/template actually renders the `.starfield` element (check MkDocs `theme.custom_dir` / overrides path)."],"exampleFix":"// before\nstarfield.setup({ auto: true });\n\n// after\nconst el = document.querySelector('.starfield');\nif (el) starfield.setup({ container: el, auto: true });","handlingStrategy":"validation","validationCode":"// Resolve (or pass) the container before setup.\nconst container = document.querySelector('.starfield');\nif (container) {\n  starfield.setup({ container, auto: false });\n}","typeGuard":"function starfieldContainerReady(config) {\n  const el = (config && config.container) || document.querySelector('.starfield');\n  return el instanceof HTMLElement;\n}","tryCatchPattern":"try {\n  starfield.setup(userConfig);\n} catch (e) {\n  if (e instanceof Error && /No container element found/.test(e.message)) {\n    // render a placeholder or skip the effect\n  } else throw e;\n}","preventionTips":["Run setup after DOMContentLoaded or with a deferred script.","Pass `{ container: el }` explicitly in SPAs after each route render.","Confirm the theme override actually emits the `.starfield` element.","Re-query the container on every init; do not cache across navigation."],"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"}