11<script setup lang="ts">
22import { createPlaceholderFromHash , lazyLoad } from ' unlazy'
33import type { ImgHTMLAttributes } from ' vue'
4- import { onBeforeUnmount , ref , useRuntimeConfig , watchEffect } from ' #imports'
4+ import { computed , onBeforeUnmount , ref , useRuntimeConfig , watchEffect } from ' #imports'
55
66const props = withDefaults (
77 defineProps <{
@@ -53,13 +53,13 @@ const props = withDefaults(
5353 },
5454)
5555
56- // SSR-decoded BlurHash as PNG data URI placeholder image
5756const { unlazy } = useRuntimeConfig ().public
58- const hash = props .thumbhash || props .blurhash
59- const loadSSR = process .server && (props .ssr ?? unlazy .ssr )
60- const pngPlaceholder = (loadSSR && hash )
57+ const hash = computed (() => props .thumbhash || props .blurhash )
58+
59+ // SSR-decoded BlurHash as PNG data URI placeholder image
60+ const pngPlaceholder = (process .server && (props .ssr ?? unlazy .ssr ) && hash .value )
6161 ? createPlaceholderFromHash ({
62- hash ,
62+ hash: hash . value ,
6363 hashType: props .thumbhash ? ' thumbhash' : ' blurhash' ,
6464 size: props .placeholderSize || unlazy .placeholderSize ,
6565 ratio: props .placeholderRatio ,
@@ -68,18 +68,18 @@ const pngPlaceholder = (loadSSR && hash)
6868
6969const target = ref <HTMLImageElement | undefined >()
7070let cleanup: () => void | undefined
71- let hasPlaceholder = false
71+ let lastHash : string | undefined
7272
7373watchEffect (() => {
7474 cleanup ?.()
7575
7676 if (! target .value )
7777 return
7878
79- if (! hasPlaceholder ) {
79+ if (hash . value && hash . value !== lastHash ) {
8080 const placeholder = createPlaceholderFromHash ({
8181 image: target .value ,
82- hash: props . thumbhash || props . blurhash ,
82+ hash: hash . value ,
8383 hashType: props .thumbhash ? ' thumbhash' : ' blurhash' ,
8484 size: props .placeholderSize || unlazy .placeholderSize ,
8585 ratio: props .placeholderRatio ,
@@ -88,7 +88,7 @@ watchEffect(() => {
8888 if (placeholder )
8989 target .value .src = placeholder
9090
91- hasPlaceholder = true
91+ lastHash = hash . value
9292 }
9393
9494 if (! props .lazyLoad )
0 commit comments