-
Notifications
You must be signed in to change notification settings - Fork 1k
[lit-html] Re-work async directives for better gc behavior #2044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 0b6386b The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
|
| const newPart = insertPart(part); | ||
| setChildPartValue(newPart, v); | ||
| i++; | ||
| // Override point for AsyncReplace to replace rather than append |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments here are confusing since this is AsyncAppend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made AsyncAppend subclass AsyncReplace since it's mostly identical code. As you can see in AsyncAppend, the only differences are:
validatePartType: AsyncReplace can be used anywhere but AsyncAppend can only go inChildPartpositionupdate: AsyncAppend needs to save the__childPartsince it inserts new parts into itcommitValue: AsyncAppend inserts new parts for each value, whereas AsyncReplace just callssetValueand overwrites the previous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-works the disconnection handling for first-party
AsyncDirectives(until,asyncAppend,asyncReplace) to use a WeakMap to connect an awaited promise's resolver and the directive that is awaiting it, so that a disconnected directive (and all of the DOM it references via its part) is not prevented from being GC'ed until its awaited promise resolves.This effectively means they will have the previous behavior of deferring their commit until they are re-connected, but with the benefit of not leaking their DOM while disconnected.
Follow-on to #2034.