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

Cannot clearError from useLazyAsyncData, how to handdle error in useLazyAsyncData? #21890

Closed
trandaison opened this issue Jul 2, 2023 · 3 comments

Comments

@trandaison
Copy link

trandaison commented Jul 2, 2023

Environment


  • Operating System: Linux
  • Node Version: v16.20.0
  • Nuxt Version: 3.6.1
  • Nitro Version: 2.5.2
  • Package Manager: npm@9.4.2
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-vcwesf?file=pages%2Fexample.vue

Describe the bug

Check out the reproduction link.

Step 1: Click Go to /example
Step 2: Click Next page, useLazyAsyncData will raises an error on the 2nd page, the error screen appears.
Step 3: Click Clear error, it will redirect to the home page.
Step 4: Click Go to /example again, and it still showing the error.

I'm not sure this is a bug or might be I'm miss understand about handling error.
The docs does't show how to handle error during fetching data with useLazyAsyncData and useAsyncData, I'm assuming that handling the error is similar to the data one, like this:

const { data, error } = await useLazyAsyncData(() => /* ... */);

watch(
  error,
  (value) => {
    if (value) showError(value);
  },
  { immediate: true }
);

Can anyone explain the case and show me the right way to handle the error in useLazyAsyncData and useAsyncData.

I think the docs should add some examples for this too.

Additional context

In the step number 2, if I click the Tigger Error button instead of next page, then in the step 4, it will work correctly.

Logs

No response

@stackblitz
Copy link

stackblitz bot commented Jul 2, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@trandaison trandaison changed the title Cannot clearError from useLazyAsyncData, how to handdle error in useLazyAsyncData and useAsyncData? Cannot clearError from useLazyAsyncData, how to handdle error in useLazyAsyncData? Jul 2, 2023
@trandaison
Copy link
Author

I confirm that this is not happen with useAsyncData, only with useLazyAsyncData.

Some workaround is reset the error object when the component unmounts.

onUnmounted(() => (error.value = null));

@danielroe
Copy link
Member

I think the underlying issue here is the same as #20979 - let's track there.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 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

2 participants