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

If the request is canceled, it won't happen again, [ signal abortController] #2837

Open
vaynevayne opened this issue Nov 16, 2023 · 0 comments

Comments

@vaynevayne
Copy link

vaynevayne commented Nov 16, 2023

Assuming I canceled the previous request, it should have been initiated again, but it didn't, is this something swr didn't take into account? Or is there a configuration parameter I should add?

swr: 2.1.5

 <SWRConfig
      value={{
        revalidateIfStale: false,
        revalidateOnFocus: false,
        revalidateOnReconnect: false,
        shouldRetryOnError: false,
      }}
    >
      <App />
    </SWRConfig>

export const requestFilters = async ([url], perPage = 400): Promise<any[]> => {
  return axios
    .get(url, {
      params: {
        perPage,
      },
    })
    .then((response) => {
      return response.data?.total > perPage
        ? requestFilters([url], response.data?.total)
        : (response.data.data || []).map((item) => ({
            label: item.label,
            value: item.key,
          }))
    })
}

export const useOptions = (name, game_Id = '') => {
  const gameId = useSessionStore((state) => state.gameId)

  return useSWR([`/filters/options?name=${name}&game_id=${game_Id || gameId}`], requestFilters, {
    revalidateIfStale: false,
    revalidateOnFocus: false,
    revalidateOnReconnect: false,
  })
}

export const  abortControllers = []

axios.interceptors.request.use(async function (request) {
  // await refreshToken()
  const controller = new AbortController()
  abortControllers.push(controller)


  request.signal = controller.signal

  return request
})


  const handlerSubmit = async () => {
    while (abortControllers.length) {
      abortControllers.pop()?.abort()
    }
    await onSubmit(values)
  }
image
@vaynevayne vaynevayne changed the title If the request is canceled, it won't happen again and revalidateIfStale: false, If the request is canceled, it won't happen again custom abortController Nov 16, 2023
@vaynevayne vaynevayne changed the title If the request is canceled, it won't happen again custom abortController If the request is canceled, it won't happen again, [ signal abortController] Nov 16, 2023
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

No branches or pull requests

1 participant