facebook / facebook/relay

Query from useRefetchableFragment is not permanently retained within the component lifecycle

Open
#4,729 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

When a refetch query is executed from `useRefetchableFragment` there is a [temporaryRetain](https://github.com/facebook/relay/blob/main/packages/react-relay/relay-hooks/QueryResource.js#L291) of the cache entry, however this is not paired with a corresponding [permanentRetain](https://github.com/facebook/relay/blob/main/packages/react-relay/relay-hooks/QueryResource.js#L316) during the components lifecycle.

This means after 5 minutes of idle time the cache entry is cleared, and upon the next render the entry will be read from the store and reinvoke the `onComplete` callback of any attached observable.

Here is an example reproducing the bug https://github.com/kyle-painter/relay-examples/commit/09965ae6e0b7e16188a77eff1a078ad81c75b497. To reproduce:
1. Press the 'Refetch' button and observe the onComplete alert dialog is shown.
![Kapture 2024-07-01 at 14 49 40](https://github.com/facebook/relay/assets/5410189/4fad2f18-31af-4ddd-9c86-7adb89804b65)

2. Wait 5 minutes.
3. Press the 'Rerender' button and observe the onComplete alert dialog is **unexpectedly** shown again.
![Kapture 2024-07-01 at 14 56 10](https://github.com/facebook/relay/assets/5410189/92be6211-24bb-451d-ba63-ab145b24c820)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.