Skip to content

Commit e112cf3

Browse files
committed
Use document as the parking node
1 parent 4d091e6 commit e112cf3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/lit-html/src/lit-html.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,6 @@ const walker = d.createTreeWalker(
634634
false
635635
);
636636

637-
// A node that we use to "park" the above TreeWalker at. This prevents the
638-
// TreeWalker from holding onto the DOM tree that we're processing after we're
639-
// done. This is necessary because we keep one TreeWalker instance for all tree
640-
// walks as a performance optimization.
641-
const walkerParkingNode = createMarker();
642-
643637
let sanitizerFactoryInternal: SanitizerFactory = noopSanitizer;
644638

645639
//
@@ -1011,7 +1005,9 @@ class Template {
10111005
}
10121006
nodeIndex++;
10131007
}
1014-
walker.currentNode = walkerParkingNode;
1008+
// We could set walker.currentNode to another node here to prevent a memory
1009+
// leak, but every time we prepare a template, we immediately render it
1010+
// and re-use the walker in new TemplateInstance._clone().
10151011
debugLogEvent?.({
10161012
kind: 'template prep',
10171013
template: this,
@@ -1162,7 +1158,10 @@ class TemplateInstance implements Disconnectable {
11621158
nodeIndex++;
11631159
}
11641160
}
1165-
walker.currentNode = walkerParkingNode;
1161+
// We need to set the currentNode away from the cloned tree so that we
1162+
// don't hold onto the tree even if the tree is detached and should be
1163+
// freed.
1164+
walker.currentNode = d;
11661165
return fragment;
11671166
}
11681167

0 commit comments

Comments
 (0)