Replies: 1 comment
-
|
Sorry it was another my fault... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context:
I'm using Next.js (SSG) with TanStack Query. I have a standard conditional rendering pattern based on the query state. During the build process, I'm encountering a
Prerender Errorbecause the code enters a block containing browser-only APIs (alert,router.push).Code Snippet:
The Issue:
During the Next.js build process (SSG), I expected the renderer to stop at Block A because
isLoadingshould betrueby default when no initial data or hydration is provided.However, it seems the renderer bypasses Block A and executes Block B, hitting the
alert()androuter.push()which are not defined on the server, leading to a build failure.My Questions (Focusing on Internal Mechanism):
I am aware that moving side effects into
useEffector usingtypeof window !== 'undefined'checks would "fix" the error. However, I want to understand the underlying mechanism:isLoadingcondition and enter the!data || isErrorblock during the server-side build? DoesuseQueryimmediately transition to a non-loading state (likestatus: 'error'or just empty data) on the server if noprefetchQueryis used?isLoadingistrueduring the first render on the server? Or does the absence of afetchenvironment cause it to resolve to "no data" instantly?loadingstatus when it detects a non-browser environment?I'd love to understand why this happens internally to write more robust SSR/SSG-friendly code. Thanks!
Note to Maintainers:
I suspect this behavior might be closely tied to Next.js's specific pre-rendering engine, but I'm reaching out here to understand the internal state management of TanStack Query in non-browser environments. If this is strictly a Next.js-side behavior, I apologize for the noise, but any insight into how
useQueryinitializes its state on the server would be immensely helpful!Thank you for your time and for maintaining such a great library.
Beta Was this translation helpful? Give feedback.
All reactions