From 7e4c804184fe214301737dbc01d101e3801f95ff Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Sun, 14 Jan 2024 10:04:05 +0100 Subject: [PATCH] :bug: :hammer: `O.el` --- src/observables-lib.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/observables-lib.js b/src/observables-lib.js index 21538f9..cc1d7fa 100644 --- a/src/observables-lib.js +++ b/src/observables-lib.js @@ -96,7 +96,7 @@ observable.el= function(o, map){ out.append(mark_start, mark_end); const { current }= scope; const reRenderReactiveElement= v=> { - if(!mark_start.parentNode || !mark_end.parentNode) + if(!mark_start.parentNode || !mark_end.parentNode) // isConnected or wasn’t yet rendered return removeObservableListener(o, reRenderReactiveElement); scope.push(current); let els= map(v); @@ -107,12 +107,21 @@ observable.el= function(o, map){ while(( el_r= mark_start.nextSibling ) !== mark_end) el_r.remove(); mark_start.after(...els); + if(mark_start.isConnected) + requestCleanUpReactives(current.host()); }; addObservableListener(o, reRenderReactiveElement); removeObservablesFromElements(o, reRenderReactiveElement, mark_start, map); reRenderReactiveElement(o()); return out; }; +function requestCleanUpReactives(host){ + if(!host || !host[key_reactive]) return; + (requestIdleCallback || setTimeout)(function(){ + host[key_reactive]= host[key_reactive] + .filter(([ o, el ])=> el.isConnected ? true : (removeObservableListener(...o), false)); + }); +} import { on } from "./events.js"; import { observedAttributes } from "./helpers.js"; const observedAttributeActions= {