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

Bypass Error in Nuxt 3 #114

Closed
YuLogun opened this issue Aug 12, 2022 · 3 comments
Closed

Bypass Error in Nuxt 3 #114

YuLogun opened this issue Aug 12, 2022 · 3 comments

Comments

@YuLogun
Copy link

YuLogun commented Aug 12, 2022

Hi!
I cannot understand the example in docs regarding bypassing errors https://github.com/unjs/ohmyfetch#%EF%B8%8F-handling-errors

My use case is the following:
In my Nuxt 3 app I have a filter on the page (it consists of several selects). Whenever the filter changes, I use its values (debouncedFetchQuery.value) to fetch data (with Nuxt 3 useAsyncData composable):

let controller = new AbortController();
const authToken = computed(() => authStore.authToken);
const {
    data: categories,
    pending: isCategoriesPending,
    refresh,
    error: categoriesError
} = await useAsyncData('fetch-categories-key', () => $fetch('/api/transactions', {
    baseURL,
    params: debouncedFetchQuery.value,
    signal: controller.signal,
    headers: { Token: authToken.value || '' }
}), {
    initialCache: false
});

let pendingRefresh = null;
watch(debouncedFetchQuery, async () => {
    if (isCategoriesPending.value) {
        controller.abort();
        controller = new AbortController();
    }

    if (pendingRefresh) {
        await pendingRefresh;
    }
    pendingRefresh = refresh();
});

The problem I have is that whenever request aborts, useAsyncData returns null for data and its subsequent component disappears from the page until the next successful request.

I wonder if it's possible to bypass Abort errors so as Nuxt composable would ignore them?

@YuLogun YuLogun changed the title Bypass Error in Nuxt Bypass Error in Nuxt 3 Aug 12, 2022
@YuLogun
Copy link
Author

YuLogun commented Aug 12, 2022

My solution for now is the following:

const categoriesOptions = ref();
watch(() => categories.value, () => {
    if (categories.value) {
        // update categoriesOptions here for page render
    }
});

@NozomuIkuta NozomuIkuta added question Further information is requested and removed question Further information is requested labels Jan 11, 2023
@NozomuIkuta
Copy link
Member

NozomuIkuta commented Jan 12, 2023

I feel this issue is potentially related to and/or duplicate of #160.
But, we appreciate if you provide a minimal reproduction by which everyone can see what you see.

@pi0
Copy link
Member

pi0 commented Aug 23, 2023

Let's track via #160 (or feel free to open an issue/question in nuxt/nuxt and ping me 👍🏼 )

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants