-
Notifications
You must be signed in to change notification settings - Fork 360
Communication: Fix conversations not keeping scroll position when opened
#12283
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
base: develop
Are you sure you want to change the base?
Changes from 7 commits
7220f5e
8947dda
cad58bc
94e8116
1f19ec6
497cefc
4397d61
ebeb76a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,18 @@ export class ConversationMessagesComponent implements OnInit, AfterViewInit, OnD | |
| childList: true, | ||
| subtree: true, | ||
| }); | ||
|
|
||
| const resizeObserver = new ResizeObserver((event, observer) => { | ||
| const entry = event.first(); | ||
| if (entry && entry.contentRect.height) { | ||
|
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. I see you're using a |
||
| // Stop observing as soon as height is non-zero | ||
|
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. I see you're using a |
||
| observer.unobserve(el); | ||
| } | ||
| if (!this.createdNewMessage && this.posts.length > 0) { | ||
| this.scrollToStoredId(); | ||
| } | ||
| }); | ||
| resizeObserver.observe(el); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| ngOnDestroy(): void { | ||
|
|
@@ -264,6 +276,8 @@ export class ConversationMessagesComponent implements OnInit, AfterViewInit, OnD | |
| } | ||
| if (savedScrollId) { | ||
| requestAnimationFrame(() => this.goToLastSelectedElement(savedScrollId, this.isOpenThreadOnFocus)); | ||
| } else { | ||
| this.scrollToBottomOfMessages(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 see you're using a
ResizeObserverhere to wait for the component to have a height before trying to restore the scroll position. That's a clever and robust way to handle this kind of race condition where layout isn't ready onngAfterViewInit. I'll keep this pattern in mind for similar issues in the future.