Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support signal on getDocument(s) to cancel requests #881

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Aug 14, 2024

Allows cancelling getDocument and getDocuments with an AbortController when using the promise API:

import {createClient} from '@sanity/client'
import {useEffect} from 'react'

const client = createClient({ /* ... */ })

const [document, setDocument] = useState(null)
useEffect(() => {
  const controller = new AbortController()
  client.getDocument('abc123', {signal: controller.signal}).then(setDocument)
  return () => controller.abort()
}, [])

The ObservableSanityClient doesn't need this, as it automatically cancels inflight requests when the observer no longer has any subscribers.

@stipsan stipsan enabled auto-merge August 14, 2024 12:37
@stipsan stipsan added this pull request to the merge queue Aug 14, 2024
Copy link
Member

@rdunk rdunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Merged via the queue into main with commit 13d71bb Aug 14, 2024
15 checks passed
@stipsan stipsan deleted the improve-abort-signal-support branch August 14, 2024 12:51
@ecospark ecospark bot mentioned this pull request Aug 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants