Unmounting one of multiple components that share a duplicate query deletes RecordSource records
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
If you include two `QueryRenderer`s on a page that have the same query, and then you remove one, it deletes the store data associated with the component because `fetchQueryAndComputeStateFromProps` in `ReactRelayQueryRenderer.jsx` doesn't properly handle duplicate requests from different components.
When `fetchQueryAndComputeStateFromProps` is called the first time, it calls `fetch` in `ReactRelayQueryFetcher`, which then calls `execute`. After the environment executes, eventually `environment.retain` is called in `ReactRelayQueryFetcher.execute`, which retains the returned data in the `RelayMarkSweepStore` (assuming you are using the normal store setup). The second time `fetchQueryAndComputeStateFromProps` is called it does not call `execute` because the query matches an in-flight request. Therefore, the data is not retained a second time in the `RelayMarkSweepStore`. When you unmount either component, it `dispose`s the selector in `RelayMarkSweepStore`, which performs a `gc`, deleting the data for all remaining components.
I attempted to create a repro of this, but the glitch site linked in the Issues description is extremely out of date and doesn't support Relay Modern. The above was determined using Relay 1.7.0.
Contributor guide
Assessment
This issue has not been assessed yet.