Make ContextRoot deduplicate context requests by element and callback identity#3451
Merged
justinfagnani merged 9 commits intomainfrom Feb 4, 2023
Merged
Make ContextRoot deduplicate context requests by element and callback identity#3451justinfagnani merged 9 commits intomainfrom
justinfagnani merged 9 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: e7abc22 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
📊 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
|
justinfagnani
commented
Nov 11, 2022
Member
kevinpschaaf
left a comment
There was a problem hiding this comment.
Let's either skip Context tests on IE11 and document that the Context package doesn't work on IE11 / older browsers, or else document needing a WeakRef polyfill
This gets us Safari 14
Collaborator
Author
|
@kevinpschaaf PTAL |
Co-authored-by: Kevin Schaaf <kschaaf@google.com>
auto-merge was automatically disabled
February 4, 2023 01:51
Base branch requires signed commits
Merged
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.
Fixes #2765
This deduplicates context requests by element identity and callback identity, so that if an element moves around the DOM, causing it to fire multiple context-request events before a provider is available, its context callback is only called once. This behavior is similar to addEventListener() which will call a callback only once no matter how many times it's added for a single event.
This PR also fixes a potential memory leak by using WeakRefs to hold on to both elements and their context request callbacks. We need WeakRefs because when we receive a context-provider event we need to loop over all element/callback pairs for that context and dispatch events. WeakMaps do not allow iterating over entries.
cc @benjamind