Skip to content

(urql) - Fix subscription fetching lifecycle - #3902

Draft
zenios wants to merge 1 commit into
urql-graphql:mainfrom
zenios:agent/fix-subscription-fetching-lifecycle
Draft

(urql) - Fix subscription fetching lifecycle#3902
zenios wants to merge 1 commit into
urql-graphql:mainfrom
zenios:agent/fix-subscription-fetching-lifecycle

Conversation

@zenios

@zenios zenios commented Aug 17, 2026

Copy link
Copy Markdown

Summary

Restore the documented useSubscription fetching lifecycle:

  • fetching remains true while the subscription source is active, including after payloads
  • fetching becomes false when the active source completes
  • local React effect cleanup does not masquerade as upstream completion
  • results from stale sources cannot update a replacement subscription

Operation results do not carry a React hook fetching field, so computeNextState currently coerces the flag to false on every payload. Conversely, the completion handler uses !!source, but the configured source remains truthy after it has completed, causing completion to report true.

This restores the lifecycle originally discussed in #407 and implemented in #410 while retaining safe source replacement and Strict Mode behavior.

Set of changes

  • Track the effect's active source and ignore stale updates
  • Apply fetching: true after processing subscription payloads, preserving payload errors
  • Set only fetching: false on genuine upstream completion
  • Mark local cleanup before unsubscribing so onEnd is not interpreted as remote completion
  • Add regression tests for payloads, completion, error preservation, and React Strict Mode cleanup
  • Add a patch changeset for urql

This is not a breaking change; it aligns runtime behavior with the existing UseSubscriptionState.fetching documentation.

Validation

  • pnpm --filter urql test --run — 59 tests passed
  • pnpm --filter urql check
  • pnpm --filter urql lint
  • pnpm --filter urql build
  • pnpm changeset status

@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6758b0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
urql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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