Skip to content

Commit

Permalink
Prevent interpreting an array which has the same object multiple time…
Browse files Browse the repository at this point in the history
…s as a circular structure

This prevents interpreting an array which has the same object multiple times as a circular structure by only checking one of these identical objects.
Increases computational complexity quite a bit though, but if this is only used in dev mode it might be fine.
  • Loading branch information
m-lautenbach committed Aug 20, 2020
1 parent 07df897 commit 611066c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/next/lib/is-serializable-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ export function isSerializableProps(

const newRefs = new Map(refs)
if (
value.every((nestedValue, index) =>
isSerializable(newRefs, nestedValue, `${path}[${index}]`)
)
value.every((nestedValue, index) => {
// This prevents interpreting an array which has the same object multiple times as a circular structure
if (value.indexOf(nestedValue) === index) {
return isSerializable(newRefs, nestedValue, `${path}[${index}]`)
} else {
return true
}
})
) {
return true
}
Expand Down

0 comments on commit 611066c

Please sign in to comment.