-
Notifications
You must be signed in to change notification settings - Fork 1k
[lit-html] Fix ref bug when auto-bound class method used as as callback
#2691
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: e915bde 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
|
| // has already been rendered to a new spot. It is double-keyed on both the | ||
| // callback and the context (options.host), since we auto-bind class methods to | ||
| // options.host. | ||
| const lastElementForCallback: WeakMap< |
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.
It seems like the WeakMap setup would make more sense if it was keyed off the host first.
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.
Done
Co-authored-by: Andrew Jakubowicz <[email protected]>
AndrewJakubowicz
left a comment
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.
Reviewed - although primarily syntax and logic surrounding the issue, since lack expertise in this domain.
This is awesome! TIL! Test is fantastic, and only comments are nits and clarifying my own understanding.
AndrewJakubowicz
left a comment
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.
Brilliant!
The
WeakMapused to store the last element called to a given callback is keyed on the callback function. Since unbound LitElement class methods passed as callbacks will all have the same references between class instances, this will result in incorrect tracking of the last element per unique callback, given that callbacks called on different context's should be considered unique.The change here uses nested WeakMaps to effectively double-key the lookup on both function and context.
Fixes #2677.