facebook / facebook/relay

Can't find an optimistic response within `commitLocalUpdate` updater's store

Open
#5,014 1 comment 0 reactions 0 assignees View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Let's say you have this in your graphql schema:
```graphql
type Comment {
id: ID!
content: String!
}
```

and this in your client extension:
```graphql
extend type Comment {
selected: Boolean
}
```
When creating a comment with a mutation, you can easily create an optimistic response for the newly created `Comment`.

Let's say I want to change the `selected` field on click, I'd use `commitLocalUpdate` to do so.

```js
commitLocalUpdate(environment, store => {
const { updatableData } = store.readUpdatableFragment(fragment, comment);
updatableData.selected = true
});
```
This works for the comments from the server, but this breaks when doing so on the comment from an optimistic response:
```
Uncaught Invariant Violation: No record with client:local:0 was found. This likely indicates a problem with Relay.
```
```
Warning: A store update was detected within another store update. Please make sure new store updates aren't being executed within an updater function for a different update.
```

Could be that `commitLocalUpdate` updater's store gets its recordSource from `_recourdSource` instead of the `_optimisticSource` that is supposed to contain the optimistic responses too.

edit: experienced with relay 18.2.0.

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.