Skip to content

Commit 746252f

Browse files
fix(web): limit max height of search results (#20727)
The height of the search results element was unrestricted, which meant that the asset visibility calculations were completely incorrect. The consequence of this is that assets which should not have been visible, were. In practical terms, all assets below the viewport were rendered when they shouldn't have been which is terrible for performance. Limiting the height of the viewport fixes that calculation and assets are correctly hidden. The consequence of limiting the height of the viewport is that the intersector then incorrectly thought the scroll position was always at the end. This has been fixed by calculating the position of sliding window against the calculated asset layout container height. Co-authored-by: Alex <[email protected]>
1 parent f36efd1 commit 746252f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

web/src/lib/components/shared-components/gallery-viewer/gallery-viewer.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@
145145
146146
let lastIntersectedHeight = 0;
147147
$effect(() => {
148-
// notify we got to (near) the end of scroll
149-
const scrollPercentage =
150-
((slidingWindow.bottom - viewport.height) / (viewport.height - (document.scrollingElement?.clientHeight || 0))) *
151-
100;
148+
const scrollRatio = slidingWindow.bottom / assetLayouts.containerHeight;
152149
153-
if (scrollPercentage > 90) {
150+
// TODO: We may want to limit to an absolute value as the ratio scaling will
151+
// get weird with lots of assets. The page may be nowhere near the bottom in
152+
// absolute terms, and yet the intersection will still be triggered.
153+
if (scrollRatio > 0.9) {
154+
// Notify we got to (near) the end of scroll.
154155
const intersectedHeight = geometry?.containerHeight || 0;
155156
if (lastIntersectedHeight !== intersectedHeight) {
156157
debouncedOnIntersected();

web/src/routes/(user)/search/[[photos=photos]]/[[assetId=id]]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
{/if}
361361

362362
<section
363-
class="mb-12 bg-immich-bg dark:bg-immich-dark-bg m-4"
363+
class="mb-12 bg-immich-bg dark:bg-immich-dark-bg m-4 max-h-screen"
364364
bind:clientHeight={viewport.height}
365365
bind:clientWidth={viewport.width}
366366
bind:this={searchResultsElement}

0 commit comments

Comments
 (0)