Skip to content

Commit

Permalink
fix(b-img-lazy): blank placeholder for Firefox (closes #6320) (#6349)
Browse files Browse the repository at this point in the history
* fix(b-img-lazy): `blank` placeholder for Firefox

* Update img-lazy.js
  • Loading branch information
jacobmllr95 authored Jan 23, 2021
1 parent 98df499 commit 9b297c9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/image/img-lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HAS_INTERACTION_OBSERVER_SUPPORT } from '../../constants/env'
import { MODEL_EVENT_NAME_PREFIX } from '../../constants/events'
import { PROP_TYPE_BOOLEAN, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props'
import { concat } from '../../utils/array'
import { requestAF } from '../../utils/dom'
import { identity } from '../../utils/identity'
import { toInteger } from '../../utils/number'
import { omit } from '../../utils/object'
Expand All @@ -23,7 +24,6 @@ const imgProps = omit(BImgProps, ['blank'])
export const props = makePropsConfigurable(
{
...imgProps,
blankColor: makeProp(PROP_TYPE_STRING, 'transparent'),
blankHeight: makeProp(PROP_TYPE_NUMBER_STRING),
// If `null`, a blank image is generated
blankSrc: makeProp(PROP_TYPE_STRING, null),
Expand Down Expand Up @@ -71,14 +71,14 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
.filter(identity)
.join(',')

return !this.blankSrc || this.isShown ? srcset : null
return srcset && (!this.blankSrc || this.isShown) ? srcset : null
},
computedSizes() {
const sizes = concat(this.sizes)
.filter(identity)
.join(',')

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

// Ensure the show prop is synced (when no `IntersectionObserver`)
if (visible !== newValue) {
if (newValue !== visible) {
this.$nextTick(this.updateShowProp)
}
}
Expand All @@ -114,7 +114,11 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
// If IntersectionObserver is not supported, the callback
// will be called with `null` rather than `true` or `false`
if ((visible || visible === null) && !this.isShown) {
this.isShown = true
// In a `requestAF()` to render the `blank` placeholder properly
// for fast loading images in some browsers (i.e. Firefox)
requestAF(() => {
this.isShown = true
})
}
}
},
Expand All @@ -124,7 +128,7 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
// We only add the visible directive if we are not shown
directives.push({
// Visible directive will silently do nothing if
// IntersectionObserver is not supported
// `IntersectionObserver` is not supported
name: 'b-visible',
// Value expects a callback (passed one arg of `visible` = `true` or `false`)
value: this.doShow,
Expand All @@ -147,8 +151,8 @@ export const BImgLazy = /*#__PURE__*/ Vue.extend({
blank: this.computedBlank,
width: this.computedWidth,
height: this.computedHeight,
srcset: this.computedSrcset || null,
sizes: this.computedSizes || null
srcset: this.computedSrcset,
sizes: this.computedSizes
}
})
}
Expand Down

0 comments on commit 9b297c9

Please sign in to comment.