Skip to content

Commit

Permalink
Fix bug with "Circular Structure" error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Skn0tt authored Apr 12, 2021
1 parent c5c1649 commit 1061dc6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export class NextScript extends Component<OriginProps> {
const data = JSON.stringify(__NEXT_DATA__)
return htmlEscapeJsonString(data)
} catch (err) {
if (err.message.indexOf('circular structure')) {
if (err.message.indexOf('circular structure') !== -1) {
throw new Error(
`Circular structure in "getInitialProps" result of page "${__NEXT_DATA__.page}". https://nextjs.org/docs/messages/circular-structure`
)
Expand Down

0 comments on commit 1061dc6

Please sign in to comment.