fix(useRequest): sync loading state across components sharing the same cacheKey promise#2919
Draft
Copilot wants to merge 3 commits into
Draft
fix(useRequest): sync loading state across components sharing the same cacheKey promise#2919Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
|
|
Copilot
AI
changed the title
[WIP] Fix loading state issue with shared promise in useRequest
fix(useRequest): sync loading state across components sharing the same cacheKey promise
Mar 28, 2026
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
当多个组件使用相同
cacheKey共享 promise 时,只有发起请求的组件会显示loading: true,其他订阅同一cacheKey的组件在请求进行中始终保持loading: false。🤔 这个变动的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
问题:
cacheSubscribe的订阅回调只同步data,没有同步loading状态。当组件 A 发起新请求时,持有同一cacheKey的组件 B/C 无法感知请求开始,因此不显示 loading。根本原因:
subscribe回调只执行setState({ data }),请求完成时不将loading置为false解决方案:
cacheSubscribe.ts:新增triggerLoading/subscribeLoading,提供独立的 loading 状态订阅通道useCachePlugin.ts:onRequest:创建新 promise 时调用triggerLoading(cacheKey),通知其他组件置loading: trueuseCreation:通过subscribeLoading订阅 loading 事件;数据订阅回调同时设置loading: falseonSuccess/onMutate:重新订阅时回调同样携带loading: falseuseUnmount:同步取消 loading 订阅📝 更新日志
useRequest: fixloadingnot synced to other components sharing the samecacheKeywhen a new request is initiateduseRequest:修复通过cacheKey共享 promise 时,只有发起请求的组件loading变为true,其余组件loading保持false的问题☑️ 请求合并前的自查清单
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.