data-client: Partial update optimism not working for singleton resource

React version 16.11.0

Concurrent mode no

Describe the bug Optimism is not working on partialUpdateShape for a singleton resource.

To Reproduce

I have a singleton resource implemented as such:

export class MySingletonResource extends Resource {
  static urlRoot = "/singleton";

  pk() {
    return "MySingletonResource";
  }

  static url<T extends typeof Resource>(this: T) {
    return this.urlRoot;
  }

  readonly myProperty: boolean = false;
}

When I do:

const data = useResource(MySingletonResource.detailShape(), {});
const update = useFetcher(MySingletonResource.partialUpdateShape());
update({}, { myProperty: true });

I have to wait for the network request to finish before a rerender with the updated data (myProperty is true) is triggered. This delay is very noticeable.

Expected behavior I would expect the partial update to be applied instantaneously, instead of needing to wait for the network request to finish.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (4 by maintainers)

Most upvoted comments

@yunyu @kjanoudi @ChristopherMillon 4.3.0-beta.0 has optimistic updates. Docs here

Tell me how it works for you