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

BigInt: Error: Circular structure in "getInitialProps" #63

Closed
PeterDekkers opened this issue Apr 11, 2021 · 2 comments · Fixed by flightcontrolhq/superjson#132
Closed
Assignees

Comments

@PeterDekkers
Copy link

PeterDekkers commented Apr 11, 2021

Hello!

It seems that whenever I have a BigInt value in my data I get a server error:

Server Error
Error: Circular structure in "getInitialProps" result of page "/". https://nextjs.org/docs/messages/circular-structure
This error happened while generating the page. Any console logs will be displayed in the terminal window.

The versions I am using are:

{
  "dependencies": {
    "next": "10.1.3",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "superjson": "^1.7.3"
  },
  "devDependencies": {
    "@types/react": "^17.0.3",
    "babel-plugin-superjson-next": "^0.2.3",
    "typescript": "^4.2.4"
  }
}

Here's a minimal reproduction:

import React from "react";
import { GetStaticProps, InferGetStaticPropsType } from "next";

export const getStaticProps: GetStaticProps = async () => {
    const topics = [
        {
            post_count: BigInt("22"),
        }
    ];
    return {
        props: {
            topics
        }
    };
}

export default function Home({ topics }: InferGetStaticPropsType<typeof getStaticProps>): React.ReactElement {
    return <></>;
}
@Skn0tt Skn0tt self-assigned this Apr 12, 2021
@Skn0tt
Copy link
Member

Skn0tt commented Apr 12, 2021

Circular Structure ... seems to be a display error in Next.js.
The real error that occurs is Do not know how to serialize a BigInt. This is likely a problem with SuperJSON itself. I'll take a look at it.

Skn0tt added a commit to Skn0tt/next.js that referenced this issue Apr 12, 2021
Since `-1` is truthy, every JSON.stringify error is mistaken to be `circular structure`. This commit fixes that behaviour, so that other errors like `Do not know how to serialize Bigint` (see blitz-js/babel-plugin-superjson-next#63) aren't swallowed.
Skn0tt added a commit to flightcontrolhq/superjson that referenced this issue Apr 12, 2021
@PeterDekkers
Copy link
Author

PeterDekkers commented Apr 12, 2021

@Skn0tt thanks also for filing the bug fix in Next.js. Nice one!

Skn0tt added a commit to flightcontrolhq/superjson that referenced this issue Apr 13, 2021
Skn0tt added a commit to Skn0tt/next.js that referenced this issue Apr 13, 2021
This may be thought of as being a pretty contrived example, but it's exactly what happened in blitz-js/babel-plugin-superjson-next#63.
ijjk added a commit to vercel/next.js that referenced this issue Feb 10, 2022
* Fix bug with "Circular Structure" error

Since `-1` is truthy, every JSON.stringify error is mistaken to be `circular structure`. This commit fixes that behaviour, so that other errors like `Do not know how to serialize Bigint` (see blitz-js/babel-plugin-superjson-next#63) aren't swallowed.

* Add integration test

This may be thought of as being a pretty contrived example, but it's exactly what happened in blitz-js/babel-plugin-superjson-next#63.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
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

Successfully merging a pull request may close this issue.

2 participants