Add stateful ImageLoader component to eliminate layout shifts#60
Open
google-labs-jules[bot] wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
[CI/CD Fix Attempt 1] |
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.
Context & Rationale
Currently, publication preview images on index and detail pages lack defined dimensions. Consequently, they collapse to a height of
0pxbefore loading, causing jarring Cumulative Layout Shift (CLS) when they finally render. This visual instability degrades the user experience and impacts our SEO metrics.To solve this, this PR introduces a stateful, reusable
<ImageLoader>component. By extending our project metadata to include image dimensions, we can dynamically calculate and reserve the exact aspect ratio on page load using active skeleton placeholders. Additionally, we normalized asset paths within this component to prevent broken resource paths on nested detail pages, and added a smooth fade-in transition to eliminate abrupt loading pops.Key Decisions
bg-primary/10 animate-pulse) and a smooth fade-in transition to improve perceived application responsiveness.Detailed Changes
1. Schema & Data Pipeline
src/lib/types.ts: ExtendedProjectandResearchProjectclasses to accept an optionalimageDimensions: { width: number; height: number }parameter without breaking backwards compatibility.src/lib/helpers/projectsProvider.ts: Generated and injected an asset dimension map to automatically populateimageDimensionsfor research and fun projects before they are served to the frontend.2. Component Implementation
src/lib/components/ImageLoader.svelte: Created the stateful image loader component. It:aspect-ratiodynamically.3. View Migration
src/routes/publications/+page.svelte: Replaced standard layout-unstable<img>tags with<ImageLoader>on the publication index page.src/routes/publications/[paper]/+page.svelte: Updated the detail view hero image to use<ImageLoader>.Verification & Testing
0on both list and detail views.