facebook / facebook/relay

Unexpected suspense from useLazyLoadQuery that only spreads fragments

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

Description

Lets say we have a `useLazyLoadQuery` that only spreads other component's fragment
```
const data = useLazyLoadQuery(
graphql`
query MyQuery {
...MyFragment
}
`,
{}
)
```
if i understand correctly, this `useLazyLoadQuery` should never suspend since it does not query for any data directly which falls into the partial rendering scenario, instead, the component that uses `MyFragment` might suspend if data is not available in the cache.

However, we recently noticed that if any data that is part of the `MyFragment` got invalidated(`store.get().invalidate()`), the `useLazyLoadQuery` will start throwing promise on the next render. Looking into the [relay internals](https://github.com/facebook/relay/blob/main/packages/react-relay/relay-hooks/QueryResource.js#L410), if a query is stale, `canPartialRender` will always be false despite the query doesn't have any data dependencies. Wondering if this is by design? Thank you.

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.