{"record":{"id":"064719146442601d","repo":"leptos-rs/leptos","slug":"hot-reloading-could-not-find-replacement-node-at","errorCode":null,"errorMessage":"[HOT RELOADING] Could not find replacement node at ","messagePattern":"\\[HOT RELOADING\\] Could not find replacement node at ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"leptos_hot_reload/src/patch.js","lineNumber":273,"sourceCode":"          const range = new Range();\n          range.setStartBefore(child.start);\n          range.setEndAfter(child.end);\n          // okay this is somewhat silly\n          // if we do cloneContents() here to return it,\n          // we strip away the event listeners\n          // if we're moving just one object, this is less than ideal\n          // so I'm actually going to *extract* them, then clone and reinsert\n          /* const toReinsert = range.cloneContents();\n\t\t\t\t\tif (child.end.nextSibling) {\n\t\t\t\t\t\tchild.end.parentNode.insertBefore(toReinsert, child.end.nextSibling);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchild.end.parentNode.appendChild(toReinsert);\n\t\t\t\t\t} */\n          childNode = range.cloneContents();\n        }\n        return childNode;\n      } else {\n        console.warn(\n          \"[HOT RELOADING] Could not find replacement node at \",\n          node.Path,\n        );\n        return undefined;\n      }\n    }\n  }\n\n  function buildActualChildren(element, range) {\n    const walker = document.createTreeWalker(\n      element,\n      NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT,\n      {\n        acceptNode(node) {\n          if (\n            node.parentNode == element &&\n            (!range || range.isPointInRange(node, 0))\n          ) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/leptos_hot_reload/src/patch.js#L255-L291","documentation":"fromReplacementNode received a replacement node described only by a Path (a reference to an existing DOM node being moved) but childAtPath could not resolve that path in the current actualChildren snapshot, so it warns and returns undefined. The caller then inserts/splices `undefined` into the DOM (e.g. append(...[undefined])), which can produce the text 'Undefined' or throw later.","triggerScenarios":"A ReplaceWith/AppendChildren/InsertChild patch whose replacement is a {Path: [...]} referencing a node that no longer exists at that index — paths shifted by earlier patches in the same batch, or the path length exceeds the rebuilt children tree.","commonSituations":"Reordering or duplicating elements in a view during development; chained structural edits in one save; stale DOM after a failed earlier patch in the same batch.","solutions":["Hard-reload to reset DOM state, then re-save the file so a single clean patch batch applies.","Avoid editing multiple structural aspects of the same subtree in one save; split changes across reloads.","Check the logged node.Path against the rebuilt children structure to see which index diverged.","Update patch.js so undefined results from fromReplacementNode are filtered before DOM insertion."],"exampleFix":"// before\nconst newChildren = action.AppendChildren.map((x) => fromReplacementNode(x, actualChildren));\nchild.node.append(...newChildren);\n// after\nconst newChildren = action.AppendChildren\n  .map((x) => fromReplacementNode(x, actualChildren))\n  .filter(Boolean);\nchild.node.append(...newChildren);","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function isResolvedNode(x) {\n  return x instanceof Node;\n}","tryCatchPattern":null,"preventionTips":["Filter undefined results of fromReplacementNode before DOM insertion.","Hard-reload after reordering/duplicating large view sections.","Do not batch multiple structural edits to the same component in one save."],"tags":["hot-reload","dom-patching","leptos"],"backgroundTag":"hot-reload-path-not-found","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}