Skip to content
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

fix: chat not being scrolled to bottom (images) #4406

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## Fixed
- handle double escape on Dialog #4365
- fix random crashes on quote reply #4337
- chat not being scrolled to the very bottom upon getting opened due to images loading slowly #4406
- avoid drafts in readonly chats #4349
- fullscreen images getting cropped a little #4402, #4385

Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/components/attachment/mediaAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ export function ImageAttachment({
className='attachment-content'
src={runtime.transformBlobURL(file)}
loading='lazy'
// Pre-setting `height` and `width` from
// `message.dimensionsHeight`, as we do in the message list,
// could be used here
// to prevent layout shifts, but it's not needed,
// because this is fixed-size anyway.
/>
)}
</button>
Expand Down Expand Up @@ -301,6 +306,11 @@ export function VideoAttachment({
className='attachment-content'
src={runtime.transformBlobURL(file)}
controls={false}
// Pre-setting `height` and `width` from
// `message.dimensionsHeight`, as we do in the message list,
// could be used here
// to prevent layout shifts, but it's not needed,
// because this is fixed-size anyway.
/>
<div className='video-play-btn'>
<div className='video-play-btn-icon' />
Expand Down
28 changes: 28 additions & 0 deletions packages/frontend/src/components/attachment/messageAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import FullscreenMedia, {
import useTranslationFunction from '../../hooks/useTranslationFunction'
import useDialog from '../../hooks/dialog/useDialog'
import AudioPlayer from '../AudioPlayer'
import { T } from '@deltachat/jsonrpc-client'

type AttachmentProps = {
text?: string
Expand Down Expand Up @@ -86,6 +87,11 @@ export default function Attachment({
<img
className='attachment-content'
src={runtime.transformBlobURL(message.file)}
// Pre-set width and height to prevent layout shifts
// when the image finally loads.
// This is not supposed to affect the rendered dimensions
// of the media _after_ it has been loaded.
style={getDimensions(message)}
/>
</button>
)
Expand Down Expand Up @@ -114,6 +120,11 @@ export default function Attachment({
className='attachment-content video-content'
src={runtime.transformBlobURL(message.file)}
controls={true}
// Pre-set width and height to prevent layout shifts
// when the video finally loads.
// This is not supposed to affect the rendered dimensions
// of the media _after_ it has been loaded.
style={getDimensions(message)}
/>
</div>
)
Expand Down Expand Up @@ -217,3 +228,20 @@ export function DraftAttachment({
)
}
}

function getDimensions(
message: Pick<T.Message, 'dimensionsHeight' | 'dimensionsWidth'>
): { height: number | undefined; width: number | undefined } {
// With some sanity checks, in case core couldn't determine dimensions
// for whatever reason, but the browser might.
return {
height:
message.dimensionsHeight > 0 && message.dimensionsHeight < 100_000
? message.dimensionsHeight
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we have a limit of 100_000 here? Would 10_000 not be enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. But it's just a sanity check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe someone has 4 4K monitors stacked on top of each other on their wall 🤷‍♀️

: undefined,
width:
message.dimensionsWidth > 0 && message.dimensionsWidth < 100_000
? message.dimensionsWidth
: undefined,
}
}
Loading