离线突变后 Apollo useQuery 陷入 loading = true 状态
16m 我正在尝试使用 Apollo 完成一个强大的离线 React、PWA。
我有一个使用 useQuery 来检索项目列表的功能组件。它使用默认的 fetchPolicy。当该组件呈现时,它成功检索数据。如果我在线或离线,它就可以正常工作。
如果我处于离线状态并且调用 useMutation 来创建新项目,则列表会正确更新,因为我使用的是 optimisticResponse 和突变的更新功能。
当我离开列表组件,使其不再呈现,然后返回时,就会出现问题。返回后,列出所有项目的功能组件将再次呈现,由于我调用了突变,它陷入了 loading=true
状态。一直以来,该应用程序仍处于离线状态。在此加载状态下,我尝试在离线状态下创建另一个项目。在这种情况下,该列表永远不会乐观地更新。
我需要做什么才能让它发挥作用?我将其打造为离线优先应用程序的基本方法是否存在根本缺陷?
以下是产生问题的步骤的摘要。
- 功能组件执行查询并检索项目列表并毫无问题地呈现它们。
- 将应用程序置于离线状态。
- 当列表组件仍然呈现时,调用突变以在离线状态下创建新项目。
- 乐观地更新 UI(通过更新缓存)不会出现任何问题。
- 离开列表组件。
- 导航回列表组件(强制重新渲染整个列表组件)
- 列表组件 useQuery/loading 值停留在 true 状态。
- 尝试以与以前相同的方式创建另一个项目。
- 名单更新情况并不乐观。
我似乎无法弄清楚这一点。
16m
I am trying to complete a robust offline React, PWA using Apollo.
I have a functional component that uses useQuery to retrieve a list of items. It is using the default fetchPolicy. When this component renders, it successfully retrieves the data. If I am online or offline it works just fine.
If I am offline and I make a call to useMutation to create a new item, the list updates correctly, since I am using optimisticResponse and the update feature of mutations.
The problem happens when I navigate away from the list component, so that it is no longer rendered, then I return. Upon returning, the functional component that list all of the items is rendered again, it is stuck in the loading=true
condition since I invoked the mutation. All this time the app is still offline. While in this loading state, I try to create another item while offline. The list never optimistically updates in this situation.
What do I have to do to get this to work? Is there a fundamental flaw to my basic approach to making this an offline-first app?
Here is a summary of the steps that create the problem.
- Functional component executes a query and retrieves a list of items and renders them without issues.
- Place the app offline.
- While the list component is still rendered, invoke a mutation to create a new item while offline.
- Optimistically update the UI (by updating the cache) with no issues.
- Navigate away from the list component.
- Navigate back to the list component (forcing a rerender of the entire list component)
- The list component useQuery/loading value is stuck in true condition.
- Attempt to create another item the same way as before.
- The list does not optimistically update.
I cannot seem to figure this one out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论