Skip to content

Commit

Permalink
perf(img): memoization card and img component
Browse files Browse the repository at this point in the history
try to fix flickering img, but cannot solve it. cf. gatsbyjs/gatsby#34190
  • Loading branch information
sungik-choi committed Dec 30, 2021
1 parent 23bb18f commit 5396824
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/postGrid/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ const Desc = styled.p`
text-overflow: ellipsis;
`

export default Card
export default React.memo(Card)
12 changes: 8 additions & 4 deletions src/components/postGrid/card/centeredImg.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useMemo } from "react"
import styled from "styled-components"
import { graphql, useStaticQuery } from "gatsby"
import type { IGatsbyImageData } from "gatsby-plugin-image"
import { GatsbyImage } from "gatsby-plugin-image"
import type { IGatsbyImageData } from "gatsby-plugin-image"

import type { Query } from "Types/GraphQL"
import type Post from "Types/Post"
Expand All @@ -20,7 +20,11 @@ const CenteredImg: React.FC<CenteredImgProps> = ({ src, alt }) => {
edges {
node {
id
gatsbyImageData(aspectRatio: 1.77, placeholder: BLURRED)
gatsbyImageData(
layout: CONSTRAINED
aspectRatio: 1.77
placeholder: BLURRED
)
}
}
}
Expand All @@ -37,7 +41,7 @@ const CenteredImg: React.FC<CenteredImgProps> = ({ src, alt }) => {
return (
<ThumbnailWrapper>
<InnerWrapper>
<GatsbyImage image={image} alt={alt ?? DEFAULT_ALT} />
<GatsbyImage image={image} loading="eager" alt={alt ?? DEFAULT_ALT} />
</InnerWrapper>
</ThumbnailWrapper>
)
Expand All @@ -64,4 +68,4 @@ const InnerWrapper = styled.div`
overflow: hidden;
`

export default CenteredImg
export default React.memo(CenteredImg)

0 comments on commit 5396824

Please sign in to comment.