Skip to content
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

Query loaded with @preloadable not retained in store for long #4735

Open
alex-statsig opened this issue Jul 12, 2024 · 0 comments
Open

Query loaded with @preloadable not retained in store for long #4735

alex-statsig opened this issue Jul 12, 2024 · 0 comments

Comments

@alex-statsig
Copy link
Contributor

Context

Currently, I am using loadQuery() to prefetch a query for another page when the user hovers over navigation items. The preloaded reference is purely to prime the relay store with the query results optimistically (I'm currently using useLazyloadQuery on those pages). The loadQuery() response is disposed in the onMouseLeave() for this button to allow it to be GCed, but currently if I hover the button again it does not fire a new query due to a fetchPolicy of 'store-or-network' (and the prefetch being retained in the store for a bit, even though I've disposed the reference). I currently use the concrete request to load this query (to avoid impacting bundle sizes, this prefetching file would do an async import for the concrete request file).

With support for @preloadable in new versions of relay, I wanted to change this pre-fetch query to just directly import the preloadable concrete request to simplify logic and avoid the async import of the large concrete request. However, I'm seeing some unexpected behavior when using it.

Issue

When using loadQuery() with a preloadable concrete request (from '..Query$parameters), repeated calls to loadQuery(env, preloadableRequest, {}, {fetchPolicy: 'store-or-network') each trigger a new network request immediately once the reference is disposed. This seems to be different behavior from a non-preloadable request, which would be satisfied by the relay store on subsequent triggers even if disposed (for some window of time at least).

I can probably delay the disposal of the prefetch to avoid these repeated network calls in my case, but I'm wondering if this is expected behavior. It seems odd for the preload query to be disposed faster than a regular query, but maybe I've missed somewhere this can be configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant