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

Error not persisted during hydration #108

Open
raggesilver opened this issue Jan 10, 2025 · 0 comments
Open

Error not persisted during hydration #108

raggesilver opened this issue Jan 10, 2025 · 0 comments

Comments

@raggesilver
Copy link

Environment

Package: @hebilicious/vue-query-nuxt 0.3.0
Node: v22.12.0

Reproduction

<script setup lang="ts">

const { suspense, data, error, isPending } = useQuery({
  queryKey: ["something"],
  queryFn: () => useRequestFetch()("/respond-with-4xx")
});

if (import.meta.env.SSR) {
  await suspense();
}

// SSR: { error: "Some error message" }
// Client: { error: undefined }
console.log({ error: error.value?.message });
</script>

<template>
  <div>
    <span v-if="isPending">Loading...</span>
    <span v-else-if="error">Error: {{ error.statusMessage ?? error.message }}</span>
    <span v-else>{{ data }}</span>
  </div>
</template>

Describe the bug

When a page is rendered server side and an API call responded with an error (4xx or 5xx) the state is lost during hydration, causing a hydration mismatch error.

Here's a breakdown of the events:

  1. server renders component (by awaiting the suspense promise) and renders the error message
  2. browser loads html with error message
  3. component code is executed client-side
  4. instead of keeping the error response, useQuery sets error to null and isPending to true, causing hydration mismatch errors

Additional context

No response

Logs

No response

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