question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DehydratedState type error

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

“next”: “12.2.5” Works “next”: “^12.2.5” Fails “next”: “latest” Fails (12.3.0)

Provide environment information

Binaries: Node: 17.6.0 npm: 8.5.1 Yarn: 1.22.10 pnpm: N/A Relevant packages: next: 12.2.5 eslint-config-next: 12.2.5 react: 18.2.0 react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Amplify deploying SSR build using “next build”

Describe the Bug

Type error created when trying to reference “dehydratedState” from pageProps (using react-query) in app.tsx. Temporarily solved by changing the type of pageProps to any or reverting next to version 12.2.5

In _app.tsx,

import { AppProps } from 'next/app'; function MyApp({ Component, pageProps }: AppProps): JSX.Element { ... <Hydrate state={pageProps.dehydratedState}> ...

Worked in previous versions of next

Expected Behavior

No type error on build

Link to reproduction

bug report template with npx create next-app -e reproduction-template

To Reproduce

Create next react app, add react-query as a package

update the main app definition to use type from AppProps (imported from next/app)

function MyApp({ Component, pageProps }: AppProps): JSX.Element {

Add a default dehydratedState

<Provider store={store}> <ThemeProvider theme={theme}> <QueryClientProvider client={queryClient}> <Hydrate state={pageProps.dehydratedState}> <MainApp> <Component {...pageProps} /> </MainApp> </Hydrate> </QueryClientProvider> </ThemeProvider> </Provider>

Create an aws amplify frontend application and connect it to a branch. Configure the output directory to be .next and the build command to be “next build” or “yarn/npm build”. Ensure that amplify recognizes the new app as using SSR

Temporary Workarounds

Revert next to version 12.2.5 == or == In app.tsx, change the type of pageProps to be any OR redeclare it with a type of any before using it. i.e - function MyApp({ Component, pageProps: p }: AppProps): JSX.Element { const pageProps: any = p;

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

10reactions
filloncommented, Sep 20, 2022

Try

function MyApp({ Component, pageProps }: AppProps<{ dehydratedState: unknown }>)
8reactions
sanukjosephcommented, Oct 16, 2022
//_app.tsx

import type { AppProps } from "next/app";
import { useState } from "react";
import {Hydrate,QueryClient,QueryClientProvider,type DehydratedState} from "react-query";

function App({ Component,pageProps,}: AppProps<{ dehydratedState: DehydratedState }>) {
  const [queryClient] = useState(() => new QueryClient());

  return (
    <QueryClientProvider client={queryClient}>
      <Hydrate state={pageProps.dehydratedState}>
        <Component {...pageProps} />
      </Hydrate>
    </QueryClientProvider>
  );
}

export default App;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Next JS Error serializing `.dehydratedState.queries[0].state ...
Reason: `function` cannot be serialized as JSON. Please only return JSON serializable data types. Here is my code: // Packages import ...
Read more >
SSR | TanStack Query Docs
You must render both server and client using the same dehydrated state to ensure ... Any query with an error is automatically excluded...
Read more >
Next.js Generator - API Platform
import type { AppProps } from "next/app"; import type { DehydratedState } from "react-query"; import Layout from "../components/common/Layout"; const App ...
Read more >
Beginners Guide To React Query with Next.JS - Jarrod Watts
And another hook, useMutation to keep your read and write operations in ... error; data If your data fetching function ran successfully, ...
Read more >
React Query and TypeScript - TkDodo's blog
It's never wrong because it directly reflects the implementation. I frequently look at type definitions before I read API docs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found