Skip to content

Commit

Permalink
Fix performance on arrow click
Browse files Browse the repository at this point in the history
  • Loading branch information
iaron committed Jan 14, 2020
1 parent 072c8e4 commit 939f85a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Shelf performance when clicking on the arrows.

## [1.34.0] - 2020-01-13
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion react/Shelf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Shelf = ({
paginationDotsVisibility,
...productList,
}),
[filteredProducts, loading, isMobile, productList]
[filteredProducts, loading, isMobile, paginationDotsVisibility, productList]
)

if (loading) {
Expand Down
4 changes: 2 additions & 2 deletions react/components/ProductList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Fragment } from 'react'
import ReactResizeDetector from 'react-resize-detector'
import { IOMessage } from 'vtex.native-types'
import { useCssHandles } from 'vtex.css-handles'
import { useProductImpression } from 'vtex.product-list-context'

import {
productListSchemaPropTypes,
Expand All @@ -18,6 +17,7 @@ import GapPaddingTypes, {
getGapPaddingValues,
} from '../utils/paddingEnum'
import ShelfContent from './ShelfContent'
import ProductListEventCaller from './ProductListEventCaller'

const CSS_HANDLES = ['title']

Expand All @@ -42,7 +42,6 @@ const ProductList = ({
showTitle,
paginationDotsVisibility,
}) => {
useProductImpression()
const handles = useCssHandles(CSS_HANDLES)
return products && !products.length ? null : (
<Fragment>
Expand Down Expand Up @@ -70,6 +69,7 @@ const ProductList = ({
/>
)}
</ReactResizeDetector>
<ProductListEventCaller />
</Fragment>
)
}
Expand Down
8 changes: 8 additions & 0 deletions react/components/ProductListEventCaller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useProductImpression } from 'vtex.product-list-context'

const ProductListEventCaller = () => {
useProductImpression()
return null
}

export default ProductListEventCaller
3 changes: 2 additions & 1 deletion react/components/ShelfItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ShelfItem = ({ item, summary }) => {
const [inViewRef, inView] = useInView({
// Triggers the event when the element is 75% visible
threshold: 0.75,
triggerOnce: true,
})

const dispatch = useProductListDispatch()
Expand All @@ -39,7 +40,7 @@ const ShelfItem = ({ item, summary }) => {
if (inView) {
dispatch({ type: 'SEND_IMPRESSION', args: { product: product } })
}
}, [inView])
}, [dispatch, inView, product])

return (
<ExtensionPoint
Expand Down

0 comments on commit 939f85a

Please sign in to comment.