-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(labs/virtualizer): guard against layout updates or re-observing when disconnected #4233
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
Merged
graynorton
merged 14 commits into
lit:main
from
steverep:fix-scroller-controller-null-check
Oct 13, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
298e66b
fix(labs/virtualizer): check for null controller when correcting scro…
steverep 42bdbe2
Add changeset
steverep 4255433
Detach controller after disconnecting observers
steverep bd948b4
Remove more unnecessary non-null type assertions
steverep 4bc7b31
Nullify observers on disconnect
steverep 8b502b4
Remove another unnecessary non-null assertion
steverep 89cc788
Do not re-observe children while disconnected
steverep 0ccdf60
Revert controller and observer checks
steverep 982ac54
Check for null controller and offset parent before updating layout
steverep b548c39
Update changeset
steverep 6c3f666
Add issue references to changeset
steverep 255dceb
Merge branch 'main' into fix-scroller-controller-null-check
steverep 69c0fb4
Merge branch 'main' into fix-scroller-controller-null-check
graynorton abe6b37
Merge branch 'main' into fix-scroller-controller-null-check
graynorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@lit-labs/virtualizer': patch | ||
| --- | ||
|
|
||
| Guard against layout updates or re-observing when disconnected (fixes #4182, #3831) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,11 +331,14 @@ export class Virtualizer { | |
| ); | ||
| this._scrollEventListeners = []; | ||
| this._clippingAncestors = []; | ||
| this._scrollerController!.detach(this); | ||
| this._scrollerController?.detach(this); | ||
| this._scrollerController = null; | ||
| this._mutationObserver!.disconnect(); | ||
| this._hostElementRO!.disconnect(); | ||
| this._childrenRO!.disconnect(); | ||
| this._mutationObserver?.disconnect(); | ||
| this._mutationObserver = null; | ||
| this._hostElementRO?.disconnect(); | ||
| this._hostElementRO = null; | ||
| this._childrenRO?.disconnect(); | ||
| this._childrenRO = null; | ||
| this._rejectLayoutCompletePromise('disconnected'); | ||
| } | ||
|
|
||
|
|
@@ -550,8 +553,16 @@ export class Virtualizer { | |
| } | ||
|
|
||
| _updateLayout() { | ||
| if (this._layout) { | ||
| this._layout!.items = this._items; | ||
| // Only update the layout and trigger a re-render if we have: | ||
| // a) A layout | ||
| // b) A scrollerController, which means we're connected | ||
| // c) An offsetParent, which means we're not hidden | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be |
||
| if ( | ||
| this._layout && | ||
| this._scrollerController && | ||
| this._hostElement?.offsetParent | ||
| ) { | ||
| this._layout.items = this._items; | ||
| this._updateView(); | ||
| if (this._childMeasurements !== null) { | ||
| // If the layout has been changed, we may have measurements but no callback | ||
|
|
@@ -560,7 +571,7 @@ export class Virtualizer { | |
| } | ||
| this._childMeasurements = null; | ||
| } | ||
| this._layout!.reflowIfNeeded(); | ||
| this._layout.reflowIfNeeded(); | ||
| if (this._benchmarkStart && 'mark' in window.performance) { | ||
| window.performance.mark('uv-end'); | ||
| } | ||
|
|
@@ -821,12 +832,12 @@ export class Virtualizer { | |
| this._layoutCompleteRejecter = reject; | ||
| }); | ||
| } | ||
| return this._layoutCompletePromise!; | ||
| return this._layoutCompletePromise; | ||
| } | ||
|
|
||
| private _rejectLayoutCompletePromise(reason: string) { | ||
| if (this._layoutCompleteRejecter !== null) { | ||
| this._layoutCompleteRejecter!(reason); | ||
| this._layoutCompleteRejecter(reason); | ||
| } | ||
| this._resetLayoutCompleteState(); | ||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.