Skip to content

Commit 9b297c9

Browse files
authored
fix(b-img-lazy): blank placeholder for Firefox (closes #6320) (#6349)
* fix(b-img-lazy): `blank` placeholder for Firefox * Update img-lazy.js
1 parent 98df499 commit 9b297c9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/components/image/img-lazy.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HAS_INTERACTION_OBSERVER_SUPPORT } from '../../constants/env'
44
import { MODEL_EVENT_NAME_PREFIX } from '../../constants/events'
55
import { PROP_TYPE_BOOLEAN, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props'
66
import { concat } from '../../utils/array'
7+
import { requestAF } from '../../utils/dom'
78
import { identity } from '../../utils/identity'
89
import { toInteger } from '../../utils/number'
910
import { omit } from '../../utils/object'
@@ -23,7 +24,6 @@ const imgProps = omit(BImgProps, ['blank'])
2324
export const props = makePropsConfigurable(
2425
{
2526
...imgProps,
26-
blankColor: makeProp(PROP_TYPE_STRING, 'transparent'),
2727
blankHeight: makeProp(PROP_TYPE_NUMBER_STRING),
2828
// If `null`, a blank image is generated
2929
blankSrc: makeProp(PROP_TYPE_STRING, null),
@@ -71,14 +71,14 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
7171
.filter(identity)
7272
.join(',')
7373

74-
return !this.blankSrc || this.isShown ? srcset : null
74+
return srcset && (!this.blankSrc || this.isShown) ? srcset : null
7575
},
7676
computedSizes() {
7777
const sizes = concat(this.sizes)
7878
.filter(identity)
7979
.join(',')
8080

81-
return !this.blankSrc || this.isShown ? sizes : null
81+
return sizes && (!this.blankSrc || this.isShown) ? sizes : null
8282
}
8383
},
8484
watch: {
@@ -90,7 +90,7 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
9090
this.isShown = visible
9191

9292
// Ensure the show prop is synced (when no `IntersectionObserver`)
93-
if (visible !== newValue) {
93+
if (newValue !== visible) {
9494
this.$nextTick(this.updateShowProp)
9595
}
9696
}
@@ -114,7 +114,11 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
114114
// If IntersectionObserver is not supported, the callback
115115
// will be called with `null` rather than `true` or `false`
116116
if ((visible || visible === null) && !this.isShown) {
117-
this.isShown = true
117+
// In a `requestAF()` to render the `blank` placeholder properly
118+
// for fast loading images in some browsers (i.e. Firefox)
119+
requestAF(() => {
120+
this.isShown = true
121+
})
118122
}
119123
}
120124
},
@@ -124,7 +128,7 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
124128
// We only add the visible directive if we are not shown
125129
directives.push({
126130
// Visible directive will silently do nothing if
127-
// IntersectionObserver is not supported
131+
// `IntersectionObserver` is not supported
128132
name: 'b-visible',
129133
// Value expects a callback (passed one arg of `visible` = `true` or `false`)
130134
value: this.doShow,
@@ -147,8 +151,8 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
147151
blank: this.computedBlank,
148152
width: this.computedWidth,
149153
height: this.computedHeight,
150-
srcset: this.computedSrcset || null,
151-
sizes: this.computedSizes || null
154+
srcset: this.computedSrcset,
155+
sizes: this.computedSizes
152156
}
153157
})
154158
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy