-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with "Circular Structure" error (#23905)
* 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>
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/integration/json-serialize-original-error/pages/bigint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export async function getStaticProps() { | ||
return { | ||
props: { | ||
topics: [ | ||
{ | ||
number: '22', | ||
}, | ||
], | ||
}, | ||
} | ||
} | ||
|
||
export default function Repro(props) { | ||
props.topics[0].number = 22n // basically what happened in https://github.com/blitz-js/babel-plugin-superjson-next/issues/63 | ||
return <></> | ||
} |
15 changes: 15 additions & 0 deletions
15
test/integration/json-serialize-original-error/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-env jest */ | ||
import { nextBuild } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '..') | ||
|
||
describe('JSON Serialization', () => { | ||
test('should fail with original error', async () => { | ||
const { code, stderr } = await nextBuild(appDir, [], { stderr: true }) | ||
expect(code).toBe(1) | ||
expect(stderr).toContain('Do not know how to serialize a BigInt') | ||
}) | ||
}) |