Only clearError() in NuxtErrorBoundary works to refresh this component
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 236
- Forks
- 51
- Avg merge
- 3h 48m
- Merged PRs (30d)
- 5
Description
Context:
Run example examples\advanced\error-handling, try to use FaultyComponent.vue
<script setup>
const hasIssue = ref(true)
const fixIssue = (error) => {
hasIssue.value = false
error.value = null
}
</script>
<template>
<NuxtErrorBoundary>
<throw-error v-if="hasIssue" />
<div v-else>
Component is working ^_^
</div>
<template #error="{ error }">
Component failed to Render -_-
<button @click="fixIssue(error)">
(fix the issue)
</button>
</template>
</NuxtErrorBoundary>
</template>
When click button "(fix the issue)", UI will not change, this error will not be clear and this component can't refresh and reset.
After I read the doc, I tried to modify with "error = null", actually got same result.
const fixIssue = (error) => {
hasIssue.value = false
error = null
}
Final solution, use clearError() method from #error="{ error, clearError }", only this way will triggle component refresh and clear error.
<script setup>
const hasIssue = ref(true)
const fixIssue = (clearError) => {
hasIssue.value = false
clearError()
}
</script>
<template>
<NuxtErrorBoundary>
<throw-error v-if="hasIssue" />
<div v-else>
Component is working ^_^
</div>
<template #error="{ error, clearError }">
Component failed to Render -_-
<button @click="fixIssue(clearError)">
(fix the issue)
</button>
</template>
</NuxtErrorBoundary>
</template>
Question:
Is this the best practice for NuxtErrorBoundary usage? Or did I make any mistake to use NuxtErrorBoundary when clear error?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running examples/advanced/error-handling and inspecting FaultyComponent.vue, then compare the example with the linked Nuxt error-handling documentation. Verify whether assigning error.value = null is expected to refresh the boundary or whether clearError is required. Done means the example and documentation clearly show the supported reset behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100