[lexical-headless] Bug Fix: Use window.happyDOM.close() to ensure proper cleanup#8274
Merged
etrepum merged 2 commits intofacebook:mainfrom Apr 1, 2026
Merged
[lexical-headless] Bug Fix: Use window.happyDOM.close() to ensure proper cleanup#8274etrepum merged 2 commits intofacebook:mainfrom
etrepum merged 2 commits intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
Author
|
Note that the RSS will go up for a while especially if you create a lot of garbage quickly, but it should eventually plateau. That's just how GC languages work (at least when the object graphs are non-trivial). |
ivailop7
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
HappyDOM's Window API uses a strange convention for proper cleanup that the original withDOM implementation missed. Had Claude do the research to track this one down.
Closes #8272
Claude's research
That's the leak. Line 16:
This is a static
Mapon theWindowBrowserContextclass — a GC root. Every window created gets added to it at line 105:The only place it gets removed is line 115, inside
removeWindowBrowserFrameRelation, which is only called fromBrowserWindow[PropertySymbol.destroy](). Anddestroy()is only called fromBrowserFrameFactory.destroyFrame(), which is only reached viahappyDOM.close().So the reference chain that prevents GC is:
Every Window ever created stays in this static Map forever unless
happyDOM.close()is called.window.close()is a no-op for directly-constructed windows (it only works forwindow.open()popups), so it never triggers the cleanup.Test plan
I think it'd be fragile to write tests for this happy-dom implementation detail 🤷 I've also submitted a PR to fix the upstream root cause capricorn86/happy-dom#2121 - if that lands upstream this fix would be unobservable since GC would work as-is even with calling the no-op close