Skip to content

Comments

feat(createResources): abort method to cancel ongoing fetch requests#494

Open
siduck wants to merge 1 commit intomainfrom
fetch-abort
Open

feat(createResources): abort method to cancel ongoing fetch requests#494
siduck wants to merge 1 commit intomainfrom
fetch-abort

Conversation

@siduck
Copy link
Contributor

@siduck siduck commented Dec 4, 2025

Closes: #26

Usage

const resp = createResources()

unMounted(() => {
     resp.abort()
})
Screen.Recording.2025-12-04.at.12.00.34.PM.mov

To those who want to do this automatically , just make a wrapper over createResources()

const wrapperFetch = (opts) => {
  const resp = createResource(opts)
  onUnmounted(resp.abort)
  return resp
}

@siduck siduck changed the title feat(createResources): about method to cancel ongoing fetch requests feat(createResources): abort method to cancel ongoing fetch requests Dec 4, 2025
@siduck siduck requested a review from NagariaHussain December 4, 2025 06:34
@NagariaHussain
Copy link
Collaborator

NagariaHussain commented Dec 4, 2025

The dev has to write these unmount wrappers manually? 👀

Can we do a plugin (or hook) or something which automatically aborts? I think it should be possible at least for route changes.

@siduck
Copy link
Contributor Author

siduck commented Dec 9, 2025

The dev has to write these unmount wrappers manually? 👀

Can we do a plugin (or hook) or something which automatically aborts? I think it should be possible at least for route changes.

hm so the user can just use this wrapper of createResource

import { abortableFetch } from "frappe-ui"

const posts = abortableFetch( { url } )

@NagariaHussain
Copy link
Collaborator

That could work too. But since createResource is also a hook, maybe a config like "abortOnUnmount"?

@netchampfaris
Copy link
Contributor

@siduck @NagariaHussain

createResource was originally created to work nicely with Options API, it does not work well with composition API. That's why I created new composables. If we want abort signal support, manual API calling should be good enough for now.

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.

Cancel ongoing fetch requests in resources when component is unmounted

3 participants