Skip to content

[Bug] Relay resolver-based query data is disposed while a fragment is still in use #4967

@alina-zaieva

Description

@alina-zaieva

In our Relay-based app we are using Relay resolvers for pure client state (available synchronously) and for REST API calls, while also fetching other parts of the query from a GraphQL server. While doing so, we are experiencing an issue with resolver data being seemingly disposed from the store by GC while still being in use after several extra queries are issued, and the resolver is not executed again. We weren't able to troubleshoot/debug the issue further, but the symptoms are as follows:

  1. Relay logs a warning about being unable to read data for a fragment (actual fragment in question isn't fully deterministic and also changes when you move components around):
    Warning: Relay: Expected to have been able to read non-null data for
    fragment `...' declared in `useFragment()', since fragment reference was
    non-null. Make sure that that `useFragment()`'s parent isn't holding on to and/or passing a
    fragment reference for data that has been deleted.
    
  2. App crashes with an error immediately, since useFragment returns undefined after the warning above and it cannot be destructured.
  3. Increasing gcReleaseBufferSize value makes it so that the error takes longer to occur and is less deterministic, but as far as we could tell, it never goes away fully.

While our app is somewhat complex and also cannot be shared publicly, I have managed to create a minimal repro with the same query pattern:
alina-zaieva/relay-gc-repro

The repro repo above also has some extra details on the setup and the error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions