Skip to content

Commit

Permalink
fix: Hydration mismatch (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes authored May 6, 2022
1 parent c520c00 commit 3203911
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix hydration mismatch on PLPs at `?page=1` pagination
- A bugged vertical gap with the `EmptyState` component inside the cart ([#20](https://github.com/vtex-sites/gatsby.store/pull/20)).
- Some pages missing component styles because they weren't imported ([#20](https://github.com/vtex-sites/gatsby.store/pull/20)).
- Fix Storybook initialization (#492)
Expand Down
5 changes: 3 additions & 2 deletions src/components/sections/ProductGallery/ProductGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { usePagination, useSearch } from '@faststore/sdk'
import { useSearch } from '@faststore/sdk'
import { GatsbySeo } from 'gatsby-plugin-next-seo'
import { lazy, Suspense, useState } from 'react'
import Filter from 'src/components/search/Filter'
Expand All @@ -13,6 +13,7 @@ import { mark } from 'src/sdk/tests/mark'
import Section from '../Section'
import EmptyGallery from './EmptyGallery'
import { useDelayedFacets } from './useDelayedFacets'
import { useDelayedPagination } from './useDelayedPagination'
import { useGalleryQuery } from './useGalleryQuery'
import { useProductsPrefetch } from './usePageProducts'

Expand All @@ -31,7 +32,7 @@ function ProductGallery({ title, searchTerm }: Props) {
const { data } = useGalleryQuery()
const facets = useDelayedFacets(data)
const totalCount = data?.search.products.pageInfo.totalCount ?? 0
const { next, prev } = usePagination(totalCount)
const { next, prev } = useDelayedPagination(totalCount)

useProductsPrefetch(prev ? prev.cursor : null)
useProductsPrefetch(next ? next.cursor : null)
Expand Down
16 changes: 16 additions & 0 deletions src/components/sections/ProductGallery/useDelayedPagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { usePagination as usePaginationSDK } from '@faststore/sdk'
import { useEffect, useState } from 'react'

export const useDelayedPagination = (totalCount: number) => {
const pagination = usePaginationSDK(totalCount)
const [pag, setPag] = useState<typeof pagination>(() => ({
next: false,
prev: false,
}))

useEffect(() => {
setPag(pagination)
}, [pagination])

return pag
}

1 comment on commit 3203911

@vercel
Copy link

@vercel vercel bot commented on 3203911 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.