Skip to content

Comments

chore: Migrate Relay { cacheConfig: force true } to store-and-network fetchPolicy#11744

Merged
olerichter00 merged 1 commit intomainfrom
olerichter00/ONYX-1630/replace-relay-cacheconfig-with-fetchpolicy
Mar 21, 2025
Merged

chore: Migrate Relay { cacheConfig: force true } to store-and-network fetchPolicy#11744
olerichter00 merged 1 commit intomainfrom
olerichter00/ONYX-1630/replace-relay-cacheconfig-with-fetchpolicy

Conversation

@olerichter00
Copy link
Contributor

@olerichter00 olerichter00 commented Mar 21, 2025

This PR resolves ONYX-1630

Description

This PR replaces Relay's cacheConfig: force: true with fetchPolicy: "store-and-network" for screens using useLazyloadQuery. It also adds a few more queries to routes.tsx for prefetching.

Relay's "store-and-network" fetch policy does not seem to be supported by QueryRenderer. During testing, the component did not run a new query when the screen opened, and the query was already cached. I will further investigate and probably migrate the remaining screens that use QueryRenderer to useLazyLoadQuery.

PR Checklist

  • I have tested my changes on iOS and Android.
  • I hid my changes behind a feature flag, or they don't need one.
  • I have included screenshots or videos, or I have not changed the UI.
  • I have added tests, or my changes don't require any.
  • I added an app state migration, or my changes do not require one.
  • I have documented any follow-up work that this PR will require, or it does not require any.
  • I have added a changelog entry below, or my changes do not require one.

To the reviewers 👀

  • I would like at least one of the reviewers to run this PR on the simulator or device.
Changelog updates

Changelog updates

Cross-platform user-facing changes

iOS user-facing changes

Android user-facing changes

Dev changes

  • Migrate Relay { cacheConfig: force true } to "store-and-network" fetchPolicy (for prefetching) - ole

Need help with something? Have a look at our docs, or get in touch with us.

@ArtsyOpenSource
Copy link
Contributor

ArtsyOpenSource commented Mar 21, 2025

This PR contains the following changes:

  • Dev changes (Migrate Relay { cacheConfig: force true } to "store-and-network" fetchPolicy (for prefetching) - ole - olerichter00)

Generated by 🚫 dangerJS against 591c697

@olerichter00 olerichter00 changed the title chore: Replace Relay cacheConfig with fetchPolicy chore: Migrate Relay { cacheConfig: force true } to "store-and-network" fetchPolicy Mar 21, 2025
}

export const InboxQueryRenderer: React.FC<InboxQueryRendererProps> = memo((props) => {
const data = useLazyLoadQuery<InboxQuery>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Migrating the query renderer to useLazyLoadQuery to be able to prefetch and reload the data when the user opens the screen.


const DEFAULT_SORT_OPTION = SORT_OPTIONS[0].value as CollectionArtworkSorts

export const artworkListVariables = { count: PAGE_SIZE, sort: DEFAULT_SORT_OPTION }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracting default variables for prefetching.

@olerichter00 olerichter00 force-pushed the olerichter00/ONYX-1630/replace-relay-cacheconfig-with-fetchpolicy branch from 591c697 to 647afac Compare March 21, 2025 09:42
@olerichter00 olerichter00 changed the title chore: Migrate Relay { cacheConfig: force true } to "store-and-network" fetchPolicy chore: Migrate Relay { cacheConfig: force true } to store-and-network" fetchPolicy Mar 21, 2025
@olerichter00 olerichter00 changed the title chore: Migrate Relay { cacheConfig: force true } to store-and-network" fetchPolicy chore: Migrate Relay { cacheConfig: force true } to store-and-network fetchPolicy Mar 21, 2025
@olerichter00 olerichter00 self-assigned this Mar 21, 2025
@olerichter00 olerichter00 merged commit c82f89a into main Mar 21, 2025
6 of 7 checks passed
@olerichter00 olerichter00 deleted the olerichter00/ONYX-1630/replace-relay-cacheconfig-with-fetchpolicy branch March 21, 2025 15:43
return (
<Suspense fallback={<InboxPlaceholder />}>
<InboxQueryRenderer {...props} />
</Suspense>
Copy link
Contributor

Choose a reason for hiding this comment

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

@olerichter00 sorry for the late drive by review but I think there is a subtle but important difference here vs renderWithPlaceholder. I believe renderWithPlaceholder will render the failure view in event of errors on the same screen we are on whereas without it the error will bubble up and potentially cause app wide unable to load making tabs inaccessible. tl;dr we need an ErrorBoundary in addition to the Suspense:

export const withSuspense = <T extends Object | any>({

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the late review :)

I tested the error handling of the screen (by throwing an error inside of the component), and it looks fine to me. The "Unable to Load" screen is displayed; it's possible to reload and access other tabs. Or am I missing something?

I guess, the global error AppWideErrorBoundary handles the error with displaying the tabs correctly 🤔

Simulator.Screen.Recording.-.iPhone.16.-.2025-03-24.at.15.14.59.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

it is good it is showing the tabs, but really we shouldn't hit the app wide error boundary whenever possible which is what the error is saying and instead add an error boundary that is as local as possible to where the error occurred

Copy link
Contributor

Choose a reason for hiding this comment

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

#11035 e.g. trying to maintain as much nav as possible possibly a simpler error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense 👍 I've created a PR that adds local error boundaries with withSuspense to the Inbox and the Collection Artist screens: #11775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants