@@ -4,6 +4,7 @@ import { html, nothing } from "lit";
4
4
import { customElement , property , queryAssignedNodes } from "lit/decorators.js" ;
5
5
import { choose } from "lit/directives/choose.js" ;
6
6
import { ifDefined } from "lit/directives/if-defined.js" ;
7
+ import { keyed } from "lit/directives/keyed.js" ;
7
8
import { when } from "lit/directives/when.js" ;
8
9
9
10
import { CollectionThumbnail } from "./collection-thumbnail" ;
@@ -88,14 +89,24 @@ export class CollectionsGrid extends BtrixElement {
88
89
< div
89
90
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 "
90
91
>
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
+ }
99
110
${ this . renderDateBadge ( collection ) }
100
111
</ div >
101
112
< div class ="${ showActions ? "mr-9" : "" } min-h-9 leading-tight ">
0 commit comments