未验证 提交 76e86e0f 编写于 作者: M Markus Lautenbach 提交者: GitHub

Remove false positive in circular structure detection (#16380)

Co-authored-by: NJoe Haddad <joe.haddad@zeit.co>
上级 71c5ab62
......@@ -98,11 +98,16 @@ export function isSerializableProps(
if (Array.isArray(value)) {
visit(refs, value, path)
const seen = new Set<any>()
const newRefs = new Map(refs)
if (
value.every((nestedValue, index) =>
isSerializable(newRefs, nestedValue, `${path}[${index}]`)
)
value.every((nestedValue, index) => {
if (seen.has(nestedValue)) {
return true
}
seen.add(nestedValue)
return isSerializable(newRefs, nestedValue, `${path}[${index}]`)
})
) {
return true
}
......
......@@ -275,4 +275,13 @@ Reason: Circular references cannot be expressed in JSON (references: \`.k\`)."
})
).toBe(true)
})
it('allows identical object instances in an array', () => {
const obj = { foo: 'bar' }
const arr = [obj, obj]
const objWithArr = { deep: { arr } }
expect(isSerializableProps('/', 'test', { arr })).toBe(true)
expect(isSerializableProps('/', 'test', { objWithArr })).toBe(true)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册