@@ -57,41 +57,44 @@ const props = withDefaults(
5757
5858const { unlazy } = useRuntimeConfig ().public
5959const target = ref <HTMLImageElement | undefined >()
60+ let isLoaded = false
6061let cleanup: () => void | undefined
61- // const now = performance.now()
6262
6363// SSR-decoded BlurHash as PNG data URI placeholder image
64- const loadSSR = process .server && (props .ssr ?? unlazy .ssr )
6564const pngPlaceholder = computed (() => {
66- if (! loadSSR || (! props .blurhash && ! props .thumbhash ))
67- return
68-
69- return props .blurhash
70- ? createPngDataUriFromBlurHash (props .blurhash , {
71- size: props .placeholderSize || unlazy .placeholderSize ,
72- ratio: props .placeholderRatio ,
73- })
74- : createPngDataUriFromThumbHash (props .thumbhash ! )
65+ if (
66+ (process .client || (props .ssr ?? unlazy .ssr ))
67+ && (props .blurhash || props .thumbhash )
68+ ) {
69+ return props .blurhash
70+ ? createPngDataUriFromBlurHash (props .blurhash , {
71+ size: props .placeholderSize || unlazy .placeholderSize ,
72+ ratio: props .placeholderRatio ,
73+ })
74+ : createPngDataUriFromThumbHash (props .thumbhash ! )
75+ }
7576})
7677
77- // if (loadSSR && process.dev)
78- // console.log(`[unlazy] BlurHash decoded in ${performance.now() - now}ms`)
79-
8078onMounted (() => {
8179 if (! target .value )
8280 return
8381
8482 watchEffect (() => {
8583 cleanup ?.()
8684
85+ if (pngPlaceholder .value && ! isLoaded )
86+ target .value ! .src = pngPlaceholder .value
87+
8788 if (! props .lazyLoad )
8889 return
8990
90- cleanup = lazyLoad (target .value , {
91+ cleanup = lazyLoad (target .value ! , {
9192 hash: props .thumbhash || props .blurhash ,
9293 hashType: props .thumbhash ? ' thumbhash' : ' blurhash' ,
9394 placeholderSize: props .placeholderSize || unlazy .placeholderSize ,
9495 })
96+
97+ isLoaded = true
9598 })
9699})
97100
0 commit comments