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

Using book cover sizes to prevent layout shifting #10145

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

anna-ayn
Copy link

@anna-ayn anna-ayn commented Dec 13, 2024

Closes #9739

feature

Technical

Improvements to cover image handling:

Updates to CSS styles:

Template modifications:

Testing

  1. Navigate to pages where book covers are displayed:
  1. Verified that the book covers load with the correct dimensions.
  2. Ensured that the layout remains stable and does not shift when the images are loaded.
  3. Tested the changes on various devices and screen sizes to confirm responsiveness.

Screenshot

We have make videos demonstrating the changes and comparing with the real website of OpenLibrary;
https://drive.google.com/file/d/1RrzodyWAFDAS--mk5Y222Hjk95FYgMla/view?usp=sharing
https://drive.google.com/file/d/1BF7YWPcys6Ny2EuJ9ahkiIexsC1JjmCH/view?usp=sharing
https://drive.google.com/file/d/1UU0nRT32Oa0Bu_27FD6cN8tQES-QUqpQ/view?usp=sharing
https://drive.google.com/file/d/1qe68bcZtBNh2cbOEbi93z4s2u9XHgDtD/view?usp=sharing
https://drive.google.com/file/d/1rOheT5PNJi6iveGhcGpb589YsG9uEqXb/view?usp=drive_link

Stakeholders

@cdrini

@anna-ayn anna-ayn marked this pull request as ready for review December 13, 2024 12:26
@anna-ayn
Copy link
Author

Hi @RayBB and @cdrini,

We have completed the modifications to standardize the sizes of book covers and prevent layout shifting in various sections of the site.

We would greatly appreciate your review and feedback on these changes. Thank you!

@mekarpeles
Copy link
Member

mekarpeles commented Dec 16, 2024

Can you provide some screenshots so we can visually inspect the before/after? Thank you!

EDIT: I now see the videos! Disregard :)

Also, it seems like the commit history may need a bit of a rebase / cleanup.

@RayBB do you mind taking a first look?

anna-ayn and others added 8 commits December 16, 2024 21:36
…te of lists

Remove docs for calculating cover image dimensions in home template
…adjust image height to covers in already-lists
fix trailing spaces

Remove unnecessary blank lines in initMyBooksAffordances function
A new container is added and the size of the covers is standardized

A new container is added and the size of the covers is standardized
…static/css/components/search-result-item.less file.

applied black formatter
@anna-ayn
Copy link
Author

anna-ayn commented Dec 17, 2024

Hello @mekarpeles
No problem! We're glad you found the videos.

Regarding the commit history, we just done a rebase and cleanup.

Feel free to reach out if you have any other questions or need additional information!

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 17.42%. Comparing base (347bff9) to head (8b388aa).
Report is 173 commits behind head on master.

Files with missing lines Patch % Lines
...enlibrary/plugins/openlibrary/js/my-books/index.js 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10145      +/-   ##
==========================================
+ Coverage   17.12%   17.42%   +0.29%     
==========================================
  Files          89       89              
  Lines        4752     4799      +47     
  Branches      831      848      +17     
==========================================
+ Hits          814      836      +22     
- Misses       3428     3443      +15     
- Partials      510      520      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

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

Hey folks this is a great start!
I left a few small notes on the PR itself.

However, you also seem to have created a regression on the search results page.
Please fix that and the other comments and then I'll try to take a closer look.
Good luck!

http://localhost:8080/search?q=lewis&mode=everything
CleanShot 2024-12-17 at 14 21 02@2x

@@ -13,7 +13,7 @@ div.contentBody,
div#contentBody {
padding: 0 @contentBody-padding @contentBody-padding;
img {
max-width: 100%;
// max-width: 100%;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want this to be removed please delete it completely instead of commenting it out.

@@ -84,14 +84,12 @@
filter: blur(2px);
}
}
.bookcover {
width: 100%;
.git {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this an intentional change? Probably a typo

width: 32px;
max-width: 100%;
width: 22px;
// max-width: 100%;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, if you want this to be deleted please fully delete it.

Comment on lines 257 to 258


<style scoped>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please try to keep the changeset small by avoiding whitespace changes like this one.

…ass, Removed unnecessary whitespace changes and Fixed regression issue on search results page

Also, added a function to retrieve dimensions of a cover by its URL

docs: add docstring to get_dimensions_cover function

added newline at end of file in search-result-item.less

format imports and clean up whitespace in book_providers.py
@anna-ayn
Copy link
Author

Hi @RayBB

Thank you for your feedback! I've addressed the comments and made the necessary changes:

Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

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

I've taken one more brief look and found two issues:

  1. The cover in the search results has the wrong aspect ratio and as such is distorted.
    CleanShot 2024-12-19 at 23 26 17@2x

  2. The aspect ratio is also causing distortion in the "more by this author" section
    CleanShot 2024-12-19 at 23 27 02@2x

Please fix the two above issues.

Also, please edit your original PR testing instructions to include a complete list of (localhost) URLs where we should see the changes.

As for the code itself, I didn't look closely as @cdrini is the lead and will likely have detailed feedback on that when he reviews it.

Overall, good work on this. It's certainly not an easy task to get this working in so many places.

…e book.less

Removed unnecessary changes in custom_carousel.html

restored changes in custom_carousel.html
@anna-ayn
Copy link
Author

Hi @RayBB,

I've resolved the distortion issue with the covers. It was related to the object-fit property setted as "cover", and I've made the necessary adjustments.

Search Results

image

You might also like

@anna-ayn anna-ayn requested a review from RayBB December 20, 2024 17:54
@RayBB RayBB added the Needs: Staff / Internal Reviewed a PR but don't have merge powers? Use this. label Dec 22, 2024
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Hi @anna-ayn , awesome work on this one! Unfortunately looking into it some more, we only really want to affect the book page, eg book_cover.html. Fetching the info for the cover width/height has a cost associated with it, so we don't want to be doing too frequently. On the book page, we only have the one main cover which causes the biggest layout shift, that's the one we want to address. The other pages, eg. search, carousels, won't be able to use the currently flow to get the width/height, because it would be too expensive to fetch that info for all those covers. There is a separate project for including this info in our solr search index which will make that possible, but for I'm afraid it's not.

Apologies for the run around here! We didn't realize the cost of this when creating the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This cover is very rarely displayed, and fetching the cover size before rendering it is not worth the complexity and performance costs, I believe, so we can roll back the changes to this piece (and where ShowcaseItem is called).

Copy link
Collaborator

Choose a reason for hiding this comment

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

This won't quite work, since it's hard-coding the aspect ratio to 180 / 360, but getting the image sizes for all the covers that will appear in a carousel is likely going to be expensive. I don't think that will be worth the trouble, so let's roll back this page here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto with this one, the editions table displays quite a few edition covers, and would be expensive to fetch the sizing info for all of them, so leaving this as it was is best. There is a separate project to include width/height in our search index solr; once that is complete, then we can use the information there to do this kind of work!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto here unfortunately, this will not be able to use/display the cover width/height until it is in solr.

$if preload:
$add_metatag(tag="link", **{'rel': 'preload', 'as': 'image', 'href': src, 'imagesrcset': srcset})

<div class="coverMagic cover-animation">
<div class="coverMagic cover-animation" style="min-height: ${calculated_height}px;">
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like we'll only need to specify the aspect ratio; e.g. style="aspect-ratio: $cover_width / $cover_height;" on the <img> element. @RayBB and I tested this, and it removed the layout shift! That should simplify this up quite a bit!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto here unfortunately, this will have to be rolled back to avoid a performance hit.

@@ -577,6 +581,24 @@ def get_cover_url(ed_or_solr: Edition | dict) -> str | None:
return None


def get_dimensions_cover(url: str) -> tuple[int, int] | None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we have access to the database that contains all the cover info, instead of making a network request, it would be faster to instead make a database request.

I think calling the details method should fix this:

https://github.com/internetarchive/openlibrary/blob/8b2a94044f01b9388b96ff094559c8e4637b6d4f/openlibrary/coverstore/db.py

@cdrini cdrini added Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] and removed Needs: Staff / Internal Reviewed a PR but don't have merge powers? Use this. labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed]
Projects
Status: Someone else is working on it
Development

Successfully merging this pull request may close these issues.

Utilize cover height and width to prevent page layout shifting
9 participants