From 92db250d963a71da1f9035ba1edd2de5dfcb55d9 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Sun, 3 May 2026 06:33:28 +0200 Subject: [PATCH] losos/html: skip patch shortcut when cached DOM was wiped (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tagged-template `strings` arrays are interned by the engine, so the cache's `prev.strings === template.strings` matches forever — even when the container's children were cleared externally between renders. patch() then mutates detached nodes in `prev.parts` and silently no-ops, leaving the container blank. Add a `container.firstChild` guard before taking the patch shortcut. Falls through to the existing fresh-build path when the cache is stale. Using `container.firstChild` rather than checking a specific part's node also keeps the fast-path live for static templates with zero `${}` holes (empty parts array). Patched in `losos/html.js`, the file actually exported by package.json (`exports["./html"] → ./losos/html.js`); the duplicate copy at the repo root is unpublished and is its own problem (separate issue). --- losos/html.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/losos/html.js b/losos/html.js index ae2cd1a..829a428 100644 --- a/losos/html.js +++ b/losos/html.js @@ -43,8 +43,8 @@ export function render(container, template) { var prev = cache.get(container) - // Same template shape — patch only the holes - if (prev && prev.strings === template.strings) { + // Same template — patch holes. Skip if cached DOM was wiped (#15). + if (prev && prev.strings === template.strings && container.firstChild) { patch(prev.parts, prev.values, template.values) prev.values = template.values return