Skip to content

Commit 835dd0a

Browse files
committed
key collection thumbnails to collection ids to prevent flash of previous
thumbnail when switching pages
1 parent 022141e commit 835dd0a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

frontend/src/features/collections/collections-grid.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { html, nothing } from "lit";
44
import { customElement, property, queryAssignedNodes } from "lit/decorators.js";
55
import { choose } from "lit/directives/choose.js";
66
import { ifDefined } from "lit/directives/if-defined.js";
7+
import { keyed } from "lit/directives/keyed.js";
78
import { when } from "lit/directives/when.js";
89

910
import { CollectionThumbnail } from "./collection-thumbnail";
@@ -88,14 +89,24 @@ export class CollectionsGrid extends BtrixElement {
8889
<div
8990
class="relative mb-4 rounded-lg shadow-md shadow-stone-600/10 ring-1 ring-stone-600/10 transition group-hover:shadow-stone-800/20 group-hover:ring-stone-800/20"
9091
>
91-
<btrix-collection-thumbnail
92-
src=${ifDefined(
93-
Object.entries(CollectionThumbnail.Variants).find(
94-
([name]) => name === collection.defaultThumbnailName,
95-
)?.[1].path || collection.thumbnail?.path,
96-
)}
97-
collectionName=${collection.name}
98-
></btrix-collection-thumbnail>
92+
${
93+
// When swapping images, the previous image is retained until the new one is loaded,
94+
// which leads to the wrong image briefly being displayed when switching pages.
95+
// This removes and replaces the image instead, which prevents this at the cost of the
96+
// occasional flash of white while loading, but overall this feels more responsive.
97+
keyed(
98+
collection.id,
99+
html` <btrix-collection-thumbnail
100+
src=${ifDefined(
101+
Object.entries(CollectionThumbnail.Variants).find(
102+
([name]) =>
103+
name === collection.defaultThumbnailName,
104+
)?.[1].path || collection.thumbnail?.path,
105+
)}
106+
collectionName=${collection.name}
107+
></btrix-collection-thumbnail>`,
108+
)
109+
}
99110
${this.renderDateBadge(collection)}
100111
</div>
101112
<div class="${showActions ? "mr-9" : ""} min-h-9 leading-tight">

0 commit comments

Comments
 (0)