facebook / facebook/relay

Hooks - `useFragment` (sometimes) returns null when record is deleted

Open
#3,514 6 comments 12 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Version: `react-relay@11.0.2`

Issue: the return value for `useFragment` is null in some circumstances. The types suggest that this should not occur.

Repro in the example TODO app:
https://codesandbox.io/s/usefragment-returns-null-6tynl?file=/src/Todo.tsx:1027-1035

https://user-images.githubusercontent.com/489896/121592515-c8106980-ca08-11eb-89fb-ecff932b9fe9.mp4

Notes:
* A newly-created record can be deleted just fine. It is properly un-rendered.
* A record that existed at page load does not seem to be immediately removed from the connection, and it renders once more with `useFragment` returning `null`.

Using `@deleteEdge` (or the corresponding `updater` code, as is in the example TODO app) works fine. However, in our use case, the record also needs to be deleted in order to update other bits of UI.

Other approaches tried:
* using both `@deleteRecord` and `@deleteEdge` together (not yet supported?)
* in `updater` function, performing explicit deleteEdge and deleting the record in different orders (same result)

Thanks for reading!

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.