Skip to content

[6.x] Deduplicate RelationshipInput in-flight item-data requests#14590

Merged
jasonvarga merged 4 commits into6.xfrom
implement-pr-d
May 1, 2026
Merged

[6.x] Deduplicate RelationshipInput in-flight item-data requests#14590
jasonvarga merged 4 commits into6.xfrom
implement-pr-d

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

@jasonvarga jasonvarga commented May 1, 2026

This is one part from #14512

When the RelationshipInput component fires off requests to get item data, if there are multiple fields with the same value they would make identical requests. This could happen when there's a replicator with many of the same repeated subfield.

This change deduplicates concurrent requests so siblings share a single in-flight promise, and keeps that promise alive as long as anyone is still listening.

  • Added a module-scope inFlightRequests Map. Each entry holds the shared promise, an AbortController, and a subscriber count. The cache key is a JSON-encoded [itemDataUrl, site, sortedSelections].
  • Concurrent requests for the same key reuse the existing entry and increment its subscriber count instead of issuing a fresh request.
  • A new detachFromInFlightRequest helper decrements the count on unmount, navigation, or selection change. The shared AbortController only fires when the count reaches zero — so a leader changing selections or unmounting no longer cancels the request out from under followers.
  • Each subscriber's .then / .catch / .finally is gated on this._activeRequest === entry, so a component that has moved on to a new selection won't emit stale data or clear loading for an outdated request.
  • Map cleanup on settle and on detach are both identity-checked to avoid clobbering a newer entry that happens to share a cache key.

@jasonvarga jasonvarga merged commit 5ddd4c4 into 6.x May 1, 2026
23 checks passed
@jasonvarga jasonvarga deleted the implement-pr-d branch May 1, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant