Skip to content

Commit

Permalink
Merge pull request #15090 from artsy/revert-prefetching-artist-works
Browse files Browse the repository at this point in the history
chore: revert prefetching artist works over lazily loading
  • Loading branch information
mzikherman authored Jan 16, 2025
2 parents e6ece62 + 659af65 commit 9782d8e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1,318 deletions.
158 changes: 61 additions & 97 deletions src/Apps/Artist/Routes/WorksForSale/ArtistWorksForSaleRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,93 +21,81 @@ const ArtistWorksForSaleRoute: React.FC<
> = ({ artist }) => {
const { title, description } = artist.meta
const { match } = useRouter()
const isPrefetched = !!match.location.state?.isPrefetched

return (
<>
<ArtistMediumsTitle
defaultTitle={title}
name={artist.name ?? "Unknown Artist"}
/>

<Meta name="description" content={description} />

{isPrefetched ? (
<ArtistArtworkFilterRefetchContainer
artist={artist}
aggregations={
artist.sidebarAggregations
?.aggregations as SharedArtworkFilterContextProps["aggregations"]
}
/>
) : (
<SystemQueryRenderer<ArtistWorksForSaleRouteArtworksQuery>
query={graphql`
query ArtistWorksForSaleRouteArtworksQuery(
$artistID: String!
$aggregations: [ArtworkAggregation]
$input: FilterArtworksInput!
) {
artist(id: $artistID) {
...ArtistArtworkFilter_artist @arguments(input: $input)
sidebarAggregations: filterArtworksConnection(
aggregations: $aggregations
first: 1
) {
<SystemQueryRenderer<ArtistWorksForSaleRouteArtworksQuery>
query={graphql`
query ArtistWorksForSaleRouteArtworksQuery(
$artistID: String!
$aggregations: [ArtworkAggregation]
$input: FilterArtworksInput!
) {
artist(id: $artistID) {
...ArtistArtworkFilter_artist @arguments(input: $input)
sidebarAggregations: filterArtworksConnection(
aggregations: $aggregations
first: 1
) {
counts {
total
}
aggregations {
slice
counts {
total
}
aggregations {
slice
counts {
name
value
count
}
name
value
count
}
}
}
}
`}
variables={{
...getWorksForSaleRouteVariables(
match.params as { artistID: string },
match,
),
artistID: artist.slug,
}}
placeholder={<ArtworkFilterPlaceholder showCreateAlert />}
render={({ error, props }) => {
if (error) {
console.error(
"[ArtistWorksForSaleRoute]: Error loading artwork grid",
error,
)
return null
}
}
`}
variables={{
...getWorksForSaleRouteVariables(
match.params as { artistID: string },
match,
),
artistID: artist.slug,
}}
placeholder={<ArtworkFilterPlaceholder showCreateAlert />}
render={({ error, props }) => {
if (error) {
console.error(
"[ArtistWorksForSaleRoute]: Error loading artwork grid",
error,
)
return null
}

if (!props || !props.artist) {
return <ArtworkFilterPlaceholder showCreateAlert />
}
if (!props || !props.artist) {
return <ArtworkFilterPlaceholder showCreateAlert />
}

return (
<>
{props.artist.sidebarAggregations?.counts?.total === 0 ? (
<ArtistWorksForSaleEmptyFragmentContainer artist={artist} />
) : (
<ArtistArtworkFilterRefetchContainer
artist={props.artist}
aggregations={
props.artist.sidebarAggregations
?.aggregations as SharedArtworkFilterContextProps["aggregations"]
}
/>
)}
</>
)
}}
/>
)}
return (
<>
{props.artist.sidebarAggregations?.counts?.total === 0 ? (
<ArtistWorksForSaleEmptyFragmentContainer artist={artist} />
) : (
<ArtistArtworkFilterRefetchContainer
artist={props.artist}
aggregations={
props.artist.sidebarAggregations
?.aggregations as SharedArtworkFilterContextProps["aggregations"]
}
/>
)}
</>
)
}}
/>
)
</>
)
}
Expand All @@ -116,38 +104,14 @@ export const ArtistWorksForSaleRouteFragmentContainer = createFragmentContainer(
ArtistWorksForSaleRoute,
{
artist: graphql`
fragment ArtistWorksForSaleRoute_artist on Artist
@argumentDefinitions(
isPrefetched: { type: "Boolean!", defaultValue: false }
aggregations: { type: "[ArtworkAggregation]" }
input: { type: "FilterArtworksInput" }
) {
...ArtistArtworkFilter_artist
@arguments(input: $input)
@include(if: $isPrefetched)
fragment ArtistWorksForSaleRoute_artist on Artist {
...ArtistWorksForSaleEmpty_artist
slug
name
meta(page: ARTWORKS) {
description
title
}
sidebarAggregations: filterArtworksConnection(
aggregations: $aggregations
first: 1
) @include(if: $isPrefetched) {
counts {
total
}
aggregations {
slice
counts {
name
value
count
}
}
}
}
`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@ export function getWorksForSaleRouteVariables({ artistID }, { location }) {
aggregations,
artistID,
includeBlurHash: false,
// If the route was prefetched, we want `isPrefetched: true` so the query
// can be resolved immediately w/ the already-fetched variables.
isPrefetched: !!location?.state?.isPrefetched,
}
}
12 changes: 1 addition & 11 deletions src/Apps/Artist/artistRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,9 @@ export const artistRoutes: RouteProps[] = [
},
prepareVariables: getWorksForSaleRouteVariables,
query: graphql`
query artistRoutes_WorksForSaleQuery(
$artistID: String!
$isPrefetched: Boolean!
$aggregations: [ArtworkAggregation]
$input: FilterArtworksInput
) {
query artistRoutes_WorksForSaleQuery($artistID: String!) {
artist(id: $artistID) @principalField {
...ArtistWorksForSaleRoute_artist
@arguments(
isPrefetched: $isPrefetched
aggregations: $aggregations
input: $input
)
}
}
`,
Expand Down
Loading

0 comments on commit 9782d8e

Please sign in to comment.