Skip to content

feat: Prefetch links on Artwork screen #11650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/Components/ArtistListItem.tests.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Touchable } from "@artsy/palette-mobile"
import { ArtistListItemTestsQuery } from "__generated__/ArtistListItemTestsQuery.graphql"
import { RouterLink } from "app/system/navigation/RouterLink"
import { renderWithWrappers, renderWithWrappersLEGACY } from "app/utils/tests/renderWithWrappers"
import { resolveMostRecentRelayOperation } from "app/utils/tests/resolveMostRecentRelayOperation"
import { graphql, QueryRenderer } from "react-relay"
Expand Down Expand Up @@ -45,13 +45,13 @@ describe("ArtistListItem", () => {
it("renders without feedback without throwing an error", () => {
const tree = renderWithWrappersLEGACY(<TestRenderer />).root
resolveMostRecentRelayOperation(mockEnvironment)
expect(tree.findByType(Touchable).props.noFeedback).toBe(true)
expect(tree.findByType(RouterLink).props.noFeedback).toBe(true)
})

it("renders with feedback without throwing an error", () => {
const tree = renderWithWrappersLEGACY(<TestRenderer withFeedback />).root
resolveMostRecentRelayOperation(mockEnvironment)
expect(tree.findByType(Touchable).props.noFeedback).toBe(false)
expect(tree.findByType(RouterLink).props.noFeedback).toBe(false)
})

it("shows uploaded artworks counts when specified", () => {
Expand Down
32 changes: 9 additions & 23 deletions src/app/Components/ArtistListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
AvatarSize,
EntityHeader,
Flex,
FollowButton,
Text,
Touchable,
useColor,
} from "@artsy/palette-mobile"
import { AvatarSize, EntityHeader, Flex, FollowButton, Text, useColor } from "@artsy/palette-mobile"
import { ArtistListItemFollowArtistMutation } from "__generated__/ArtistListItemFollowArtistMutation.graphql"
import { ArtistListItem_artist$data } from "__generated__/ArtistListItem_artist.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { PlaceholderBox, PlaceholderText } from "app/utils/placeholders"
import { pluralize } from "app/utils/pluralize"
import { Schema } from "app/utils/track"
Expand Down Expand Up @@ -107,11 +99,6 @@ const ArtistListItem: React.FC<Props> = ({
)
}

const handleTap = (href: string) => {
tracks.tapArtistGroup(artist)
navigate(href)
}

let meta

if (includeTombstone) {
Expand Down Expand Up @@ -156,22 +143,21 @@ const ArtistListItem: React.FC<Props> = ({
}

return (
<Touchable
<RouterLink
noFeedback={!withFeedback}
// Only navigate if there is an href and navigation is not disabled by passing `onPress` or
to={!disableNavigation ? href : undefined}
onPress={() => {
if (onPress) {
onPress()
return
}
onPress?.()

if (href && !disableNavigation) {
handleTap(href)
tracks.tapArtistGroup(artist)
}
}}
underlayColor={color("black5")}
style={containerStyle}
>
<Flex flexDirection="row" justifyContent="space-between" alignItems="center">
<Flex flexDirection="row" justifyContent="space-between" alignItems="center" width="100%">
<Flex flex={1}>
<EntityHeader
mr={1}
Expand All @@ -191,7 +177,7 @@ const ArtistListItem: React.FC<Props> = ({
</Flex>
)}
</Flex>
</Touchable>
</RouterLink>
)
}

Expand Down
21 changes: 17 additions & 4 deletions src/app/Navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ import {
defaultArtistVariables,
} from "app/Scenes/Artist/Artist"
import { ArtistArticlesQueryRenderer } from "app/Scenes/ArtistArticles/ArtistArticles"
import { ArtistSeriesQueryRenderer } from "app/Scenes/ArtistSeries/ArtistSeries"
import { ArtistSeriesFullArtistSeriesListQueryRenderer } from "app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList"
import {
ArtistSeriesQueryRenderer,
ArtistSeriesScreenQuery,
} from "app/Scenes/ArtistSeries/ArtistSeries"
import {
ArtistSeriesFullArtistSeriesListQueryRenderer,
ArtistSeriesFullArtistSeriesListScreenQuery,
} from "app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList"
import { ArtistShowsQueryRenderer } from "app/Scenes/ArtistShows/ArtistShows"
import { ArtworkScreen, ArtworkScreenQuery } from "app/Scenes/Artwork/Artwork"
import { BrowseSimilarWorksQueryRenderer } from "app/Scenes/Artwork/Components/BrowseSimilarWorks/BrowseSimilarWorks"
import { CertificateOfAuthenticity } from "app/Scenes/Artwork/Components/CertificateAuthenticity"
import { UnlistedArtworksFAQScreen } from "app/Scenes/Artwork/Components/UnlistedArtworksFAQScreen"
import { ArtworkAttributionClassFAQQueryRenderer } from "app/Scenes/ArtworkAttributionClassFAQ/ArtworkAttributionClassFAQ"
import { ArtworkListScreen } from "app/Scenes/ArtworkList/ArtworkList"
import { ArtworkMediumQueryRenderer } from "app/Scenes/ArtworkMedium/ArtworkMedium"
import {
ARTWORK_MEDIUM_QUERY,
ArtworkMediumQueryRenderer,
} from "app/Scenes/ArtworkMedium/ArtworkMedium"
import { ArtworkRecommendationsScreen } from "app/Scenes/ArtworkRecommendations/ArtworkRecommendations"
import { AuctionBuyersPremiumQueryRenderer } from "app/Scenes/AuctionBuyersPremium/AuctionBuyersPremium"
import { AuctionResultQueryRenderer } from "app/Scenes/AuctionResult/AuctionResult"
Expand Down Expand Up @@ -113,7 +122,7 @@ import { NewWorksForYouQueryRenderer } from "app/Scenes/NewWorksForYou/NewWorksF
import { NewWorksFromGalleriesYouFollowScreen } from "app/Scenes/NewWorksFromGalleriesYouFollow/NewWorksFromGalleriesYouFollow"
import { OrderDetailsQueryRender } from "app/Scenes/OrderHistory/OrderDetails/Components/OrderDetails"
import { OrderHistoryQueryRender } from "app/Scenes/OrderHistory/OrderHistory"
import { PartnerQueryRenderer } from "app/Scenes/Partner/Partner"
import { PartnerQueryRenderer, PartnerScreenQuery } from "app/Scenes/Partner/Partner"
import {
PartnerLocationsQueryRenderer,
PartnerLocationsScreenQuery,
Expand Down Expand Up @@ -343,6 +352,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerShown: false,
},
},
queries: [ArtistSeriesScreenQuery],
},
{
path: "/artist/:artistID",
Expand Down Expand Up @@ -375,6 +385,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerTitle: "Artist Series",
},
},
queries: [ArtistSeriesFullArtistSeriesListScreenQuery],
},
{
path: "/artist/:artistID/auction-result/:auctionResultInternalID",
Expand Down Expand Up @@ -499,6 +510,7 @@ export const artsyDotNetRoutes = defineRoutes([
path: "/artwork/:artworkID/medium",
name: "ArtworkMedium",
Component: ArtworkMediumQueryRenderer,
queries: [ARTWORK_MEDIUM_QUERY],
},
{
path: "/artwork/:artworkID/browse-similar-works",
Expand Down Expand Up @@ -1173,6 +1185,7 @@ export const artsyDotNetRoutes = defineRoutes([
headerShown: false,
},
},
queries: [PartnerScreenQuery],
},
{
path: "/partner/:partnerID/artists/:artistID",
Expand Down
67 changes: 33 additions & 34 deletions src/app/Scenes/ArtistSeries/ArtistSeries.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import {
Spacer,
Flex,
Screen,
Tabs,
useScreenDimensions,
Separator,
Skeleton,
SkeletonBox,
Flex,
SkeletonText,
Separator,
Spacer,
Tabs,
useScreenDimensions,
} from "@artsy/palette-mobile"
import { ArtistSeriesQuery } from "__generated__/ArtistSeriesQuery.graphql"
import { ArtistSeries_artistSeries$key } from "__generated__/ArtistSeries_artistSeries.graphql"
import { ArtworkFiltersStoreProvider } from "app/Components/ArtworkFilter/ArtworkFilterStore"
import { PlaceholderGrid } from "app/Components/ArtworkGrids/GenericGrid"
import { ActivityErrorScreen } from "app/Scenes/Activity/components/ActivityErrorScreen"
import { ArtistSeriesArtworks } from "app/Scenes/ArtistSeries/ArtistSeriesArtworks"
import { ArtistSeriesHeaderFragmentContainer } from "app/Scenes/ArtistSeries/ArtistSeriesHeader"
import { ArtistSeriesMetaFragmentContainer } from "app/Scenes/ArtistSeries/ArtistSeriesMeta"
import { goBack } from "app/system/navigation/navigate"
import { getRelayEnvironment } from "app/system/relay/defaultEnvironment"
import { renderWithPlaceholder } from "app/utils/renderWithPlaceholder"
import { withSuspense } from "app/utils/hooks/withSuspense"
import { ProvideScreenTracking } from "app/utils/track"
import { OwnerEntityTypes, PageNames } from "app/utils/track/schema"
import { graphql, QueryRenderer, useFragment } from "react-relay"
import { graphql, useFragment, useLazyLoadQuery } from "react-relay"

interface ArtistSeriesProps {
artistSeries: ArtistSeries_artistSeries$key
Expand Down Expand Up @@ -127,29 +127,28 @@ const ArtistSeriesPlaceholder: React.FC = () => {
)
}

export const ArtistSeriesQueryRenderer: React.FC<{ artistSeriesID: string }> = ({
artistSeriesID,
}) => {
return (
<ArtworkFiltersStoreProvider>
<QueryRenderer<ArtistSeriesQuery>
environment={getRelayEnvironment()}
query={graphql`
query ArtistSeriesQuery($artistSeriesID: ID!) {
artistSeries(id: $artistSeriesID) {
...ArtistSeries_artistSeries
}
}
`}
cacheConfig={{ force: true }}
variables={{
artistSeriesID,
}}
render={renderWithPlaceholder({
Container: ArtistSeries,
renderPlaceholder: () => <ArtistSeriesPlaceholder />,
})}
/>
</ArtworkFiltersStoreProvider>
)
}
export const ArtistSeriesScreenQuery = graphql`
query ArtistSeriesQuery($artistSeriesID: ID!) {
artistSeries(id: $artistSeriesID) {
...ArtistSeries_artistSeries
}
}
`

export const ArtistSeriesQueryRenderer: React.FC<{ artistSeriesID: string }> = withSuspense({
Component: ({ artistSeriesID }) => {
const data = useLazyLoadQuery<ArtistSeriesQuery>(ArtistSeriesScreenQuery, { artistSeriesID })

if (!data.artistSeries) return null

return (
<ArtworkFiltersStoreProvider>
<ArtistSeries artistSeries={data.artistSeries} />
</ArtworkFiltersStoreProvider>
)
},
LoadingFallback: ArtistSeriesPlaceholder,
ErrorFallback: (fallbackProps) => {
return <ActivityErrorScreen headerTitle="Artist Series" error={fallbackProps.error} />
},
})
17 changes: 9 additions & 8 deletions src/app/Scenes/ArtistSeries/ArtistSeriesFullArtistSeriesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,21 @@ export const ArtistSeriesFullArtistSeriesListFragmentContainer = createFragmentC
}
)

export const ArtistSeriesFullArtistSeriesListScreenQuery = graphql`
query ArtistSeriesFullArtistSeriesListQuery($artistID: String!) {
artist(id: $artistID) {
...ArtistSeriesFullArtistSeriesList_artist
}
}
`

export const ArtistSeriesFullArtistSeriesListQueryRenderer: React.FC<{ artistID: string }> = ({
artistID,
}) => {
return (
<QueryRenderer<ArtistSeriesFullArtistSeriesListQuery>
environment={getRelayEnvironment()}
query={graphql`
query ArtistSeriesFullArtistSeriesListQuery($artistID: String!) {
artist(id: $artistID) {
...ArtistSeriesFullArtistSeriesList_artist
}
}
`}
cacheConfig={{ force: true }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we had this force: true here before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I did some research and testing and found out the following. cacheConfig={{ force: true }} is used to circumvent the cache, and with the default fetch policy (store-or-network), the prefetched data does not get used, and prefetching does not work. If the fetch policy is set to store-and-network, it works fine. I've opened a thread in Slack to find out if I can remove the force: true.

Copy link
Member

@damassi damassi Mar 17, 2025

Choose a reason for hiding this comment

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

Store and network is really nice, because it will return the cached result first, then fetch in the background, and if there's a diff it will update. Its sweet.

query={ArtistSeriesFullArtistSeriesListScreenQuery}
variables={{
artistID,
}}
Expand Down
9 changes: 4 additions & 5 deletions src/app/Scenes/ArtistSeries/ArtistSeriesMoreSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { ActionType, ContextModule, OwnerType, ScreenOwnerType } from "@artsy/co
import { Flex, FlexProps, Text, TextProps } from "@artsy/palette-mobile"
import { ArtistSeriesMoreSeries_artist$data } from "__generated__/ArtistSeriesMoreSeries_artist.graphql"
import { ArtistSeriesListItem } from "app/Scenes/ArtistSeries/ArtistSeriesListItem"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import React, { useEffect, useState } from "react"
import { TouchableOpacity } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"

Expand Down Expand Up @@ -59,16 +58,16 @@ export const ArtistSeriesMoreSeries: React.FC<ArtistSeriesMoreSeriesProps> = ({
{artistSeriesHeader}
</Text>
{totalCount > 4 && (
<TouchableOpacity
<RouterLink
to={`/artist/${artist?.internalID}/artist-series`}
onPress={() => {
if (artist.internalID) {
trackEvent(tracks.tapViewAllArtistSeries(artist?.internalID, artist?.slug))
navigate(`/artist/${artist?.internalID}/artist-series`)
}
}}
>
<Text variant="xs" underline testID="viewAll">{`View All (${totalCount})`}</Text>
</TouchableOpacity>
</RouterLink>
)}
</Flex>
{artistSeries.map((item, index) => {
Expand Down
9 changes: 4 additions & 5 deletions src/app/Scenes/Artwork/Components/ArtworkDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Spacer, Flex, Box, Text, Join } from "@artsy/palette-mobile"
import { Box, Flex, Join, Spacer, Text } from "@artsy/palette-mobile"
import { ArtworkDetails_artwork$key } from "__generated__/ArtworkDetails_artwork.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { Schema } from "app/utils/track"
import React from "react"
import { TouchableWithoutFeedback } from "react-native"
import { graphql, useFragment } from "react-relay"
import { useTracking } from "react-tracking"
import { ArtworkDetailsRow } from "./ArtworkDetailsRow"
Expand All @@ -27,11 +26,11 @@ export const ArtworkDetails: React.FC<ArtworkDetailsProps> = ({
{
title: "Medium",
value: artworkData?.mediumType?.name && (
<TouchableWithoutFeedback onPress={() => navigate(`/artwork/${artworkData.slug}/medium`)}>
<RouterLink to={`/artwork/${artworkData.slug}/medium`} disablePrefetch>
<Text variant="xs" color="black100" style={{ textDecorationLine: "underline" }}>
{artworkData?.mediumType?.name}
</Text>
</TouchableWithoutFeedback>
</RouterLink>
),
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/app/Scenes/Artwork/Components/ArtworkMakerTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex, Text } from "@artsy/palette-mobile"
import { ArtworkMakerTitle_artwork$data } from "__generated__/ArtworkMakerTitle_artwork.graphql"
import { navigate } from "app/system/navigation/navigate"
import { RouterLink } from "app/system/navigation/RouterLink"
import { Schema } from "app/utils/track"
import React, { useState } from "react"
import { TouchableWithoutFeedback } from "react-native"
Expand All @@ -15,26 +15,26 @@ interface ArtworkMakerProps {
const ArtworkMaker: React.FC<ArtworkMakerProps> = ({ artistName, href }) => {
const { trackEvent } = useTracking()

const handleArtistTap = (artistHref?: string | null) => {
if (artistHref) {
const handleArtistTap = () => {
if (href) {
trackEvent({
action_name: Schema.ActionNames.ArtistName,
action_type: Schema.ActionTypes.Tap,
context_module: Schema.ContextModules.ArtworkTombstone,
})
navigate(artistHref)
}
}

return (
<TouchableWithoutFeedback
<RouterLink
accessibilityRole="link"
accessibilityHint="Go to artist page"
disabled={!href}
onPress={() => handleArtistTap(href)}
to={href}
onPress={handleArtistTap}
>
<Text variant="lg-display">{artistName}</Text>
</TouchableWithoutFeedback>
</RouterLink>
)
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/Scenes/Artwork/Components/ArtworksInSeriesRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "__generated__/ArtworksInSeriesRail_artwork.graphql"
import { ArtworkRail } from "app/Components/ArtworkRail/ArtworkRail"
import { SectionTitle } from "app/Components/SectionTitle"
import { navigate } from "app/system/navigation/navigate"
import { extractNodes } from "app/utils/extractNodes"
import {
CollectorSignals,
Expand Down Expand Up @@ -39,8 +38,8 @@ export const ArtworksInSeriesRail: React.FC<ArtworksInSeriesRailProps> = (props)
titleVariant="md"
onPress={() => {
trackEvent(tracks.tappedHeader(artwork, firstArtistSeries))
navigate(`/artist-series/${firstArtistSeries?.slug}`)
}}
href={`/artist-series/${firstArtistSeries?.slug}`}
/>
<ArtworkRail
artworks={artworks}
Expand Down
Loading