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

_app.tsx not getting parsed data #54

Closed
1 task done
tzelon-cypator opened this issue Nov 15, 2022 · 3 comments
Closed
1 task done

_app.tsx not getting parsed data #54

tzelon-cypator opened this issue Nov 15, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@tzelon-cypator
Copy link

tzelon-cypator commented Nov 15, 2022

Verify Next.js canary release

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

Describe the bug

I'm using getServerSideProps to fetch some data and return it in props and in the _app.tsx file I want to use that data.
The problem is, I have a few bigint properties in the data but in the _app.tsx file bigint are still strings.
I checked on the page itself and the data are parsed as expected bigint are bigint.

Expected behavior

parsed the data.

Reproduction link

No response

Version

0.4.9

Config

experimental: {
      swcPlugins: [
        [
          "next-superjson-plugin",
          {
            excluded: [],
          },
        ],
      ],
    },

Additional context

next: v12.3.2-canary.43

@tzelon-cypator tzelon-cypator added the bug Something isn't working label Nov 15, 2022
@orionmiz
Copy link
Collaborator

orionmiz commented Nov 17, 2022

Do you want to get deserialized props by reading pageProps of AppProps?

If so, use the deserializeProps utility function.

// _app.tsx
import type { AppProps } from "next/app";
import { deserializeProps } from 'next-superjson-plugin/tools'

export default function App({ Component, pageProps }: AppProps) {
  const deserialized = deserializeProps(pageProps);
  // ...
  return <Component {...pageProps} />;
}

@tzelon-cypator
Copy link
Author

It seems like it stringify bigints as strings, but in the _app.tsx I get a simple deserialize object with the bigints still as string.
the object I return from getServerSideProps

{
  id: 1,
  version: 1,
  price_min: 1n,
  price_max: 999999999n,
  size_min: 1n,
  size_max: 9999999999999n,
}

what I receive in _app.tsx

{
  id: 1,
  version: 1,
  price_min: "1",
  price_max: "999999999",
  size_min: "1",
  size_max: "9999999999999",
}

@orionmiz
Copy link
Collaborator

orionmiz commented Nov 17, 2022

That's the expected consequences, not the bug.

See the _superjson property that might be included in the received value:

{
  id: 1,
  version: 1,
  price_min: "1",
  price_max: "999999999",
  size_min: "1",
  size_max: "9999999999999",
  _superjson: {values: {}} // this property contains type data
}

Actual deserialization is being done by the component in the way of referring to the _superjson property.
So you should deserialize the pageProps manually to take the original props, especially within _app.tsx.

If you can't find _superjson property in the received value or the solution above wasn't helpful,
please provide a minimal reproduction, I'll take a look at it.

@orionmiz orionmiz closed this as completed Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants