Comfy-Org / Comfy-Org/ComfyUI_frontend
teamWorkspaceStore: coalesce ensureMembersLoaded() on a shared in-flight promise keyed by workspaceId
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
Currently `ensureMembersLoaded()` in `src/platform/workspace/stores/teamWorkspaceStore.ts` (~line 540) early-returns when a fetch is already in flight, without returning or awaiting the existing promise. This means:
1. The deep-link loader in `usePricingTableUrlLoader` calls `fetchMembers()` directly (because `ensureMembersLoaded()` would early-return and leave the gate reading empty members, denying the original owner).
2. Meanwhile, `useWorkspaceUI`'s immediate-watch also fires `ensureMembersLoaded()` on mount.
3. `fetchMembers()` in the loader never adds the workspace to `loadedMemberWorkspaceIds`, so a later `ensureMembersLoaded()` issues a third `listMembers` call.
## Proposed Fix
Store a per-workspaceId in-flight promise inside `teamWorkspaceStore` (e.g., a `Map>`). When `ensureMembersLoaded()` detects a fetch is already in progress for that workspaceId, return/await the existing promise instead of early-returning void. This allows `usePricingTableUrlLoader` to switch back to `ensureMembersLoaded()` and correctly await completion through the deduped path, eliminating the redundant `listMembers` requests.
## Affected Files
- `src/platform/workspace/stores/teamWorkspaceStore.ts` — add shared in-flight promise map; update `ensureMembersLoaded()` and `fetchMembers()`
- `src/platform/cloud/subscription/composables/usePricingTableUrlLoader.ts` — swap `fetchMembers()` call back to `ensureMembersLoaded()` once coalescing is in place
## Acceptance Criteria
- [ ] `ensureMembersLoaded(workspaceId)` returns the existing in-flight promise when a fetch for that workspaceId is already in progress (no early-return void)
- [ ] A second concurrent caller awaits the same promise and receives results once the single network request completes
- [ ] `loadedMemberWorkspaceIds` is updated after the deduped fetch resolves so subsequent calls short-circuit correctly
- [ ] `usePricingTableUrlLoader` can use `ensureMembersLoaded()` instead of `fetchMembers()` and still correctly gate on `canManageSubscriptionLifecycle`
- [ ] No redundant `listMembers` requests on app boot when both the immediate-watch and deep-link loader run concurrently
## References
- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/13001
- Comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/13001#discussion_r3444857725
/cc @christian-byrne
Contributor guide
Assessment
This issue has not been assessed yet.