diff --git a/.changeset/shy-wasps-begin.md b/.changeset/shy-wasps-begin.md new file mode 100644 index 0000000000..6db2290030 --- /dev/null +++ b/.changeset/shy-wasps-begin.md @@ -0,0 +1,5 @@ +--- +'@lit-labs/ssr': patch +--- + +Fix a memory leak when patching directive constructors for SSR. diff --git a/packages/labs/ssr/src/lib/render-value.ts b/packages/labs/ssr/src/lib/render-value.ts index 1b55012d9a..1e636bb0c6 100644 --- a/packages/labs/ssr/src/lib/render-value.ts +++ b/packages/labs/ssr/src/lib/render-value.ts @@ -95,6 +95,10 @@ const patchIfDirective = (value: unknown) => { } ); patchedDirectiveCache.set(directiveCtor, patchedCtor); + // If `patchIfDirective` is called with a previously patched directive, + // the patched directive will become patched again unless it's also a key + // in the WeakMap. This line prevents a memory leak. + patchedDirectiveCache.set(patchedCtor, patchedCtor); } // This property needs to remain unminified. setDirectiveClass(value as DirectiveResult, patchedCtor);