Skip to content

Commit

Permalink
Merge pull request #9 from SectorLabs/sentry-error-fix
Browse files Browse the repository at this point in the history
Fix crash occurring when the gallery is empty
  • Loading branch information
Photonios authored Aug 22, 2019
2 parents 52cae3e + 82d4c9d commit dfc6960
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion build/image-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ var ImageGallery = function (_React$Component) {
value: function componentDidUpdate(prevProps, prevState) {
var itemsChanged = prevProps.items.length !== this.props.items.length;
if (itemsChanged) {
var coverPhotoChange = prevProps.items[prevProps.startIndex].id !== this.props.items[this.props.startIndex].id;
var prevCoverPhoto = prevProps.items[prevProps.startIndex] || {};
var newCoverPhoto = this.props.items[this.props.startIndex] || {};
var coverPhotoChanged = prevCoverPhoto.id !== newCoverPhoto.id;

if (coverPhotoChange && this.props.onItemsGalleryChange) {
// call the callback function
this.props.onItemsGalleryChange();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-image-gallery",
"version": "0.8.21-sl",
"version": "0.8.22-sl",
"description": "React carousel image gallery component with thumbnail and mobile support",
"main": "./build/image-gallery.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/ImageGallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export default class ImageGallery extends React.Component {
componentDidUpdate(prevProps, prevState) {
const itemsChanged = prevProps.items.length !== this.props.items.length;
if (itemsChanged) {
const coverPhotoChange = prevProps.items[prevProps.startIndex].id !== this.props.items[this.props.startIndex].id;
const prevCoverPhoto = prevProps.items[prevProps.startIndex] || {};
const newCoverPhoto = this.props.items[this.props.startIndex] || {};
const coverPhotoChanged = prevCoverPhoto.id !== newCoverPhoto.id;

if (coverPhotoChange && this.props.onItemsGalleryChange) {
// call the callback function
this.props.onItemsGalleryChange();
Expand Down

0 comments on commit dfc6960

Please sign in to comment.