diff --git a/packages/next/lib/is-serializable-props.ts b/packages/next/lib/is-serializable-props.ts index 25fefc050c64f0e3ffaac766fdfbfb95fd08e7aa..f0122ba52fc6781a2f918d99cf605dc2c6552fb7 100644 --- a/packages/next/lib/is-serializable-props.ts +++ b/packages/next/lib/is-serializable-props.ts @@ -98,11 +98,16 @@ export function isSerializableProps( if (Array.isArray(value)) { visit(refs, value, path) + const seen = new Set() 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 } diff --git a/test/unit/is-serializable-props.test.js b/test/unit/is-serializable-props.test.js index 89039e76fa8dd9a908fd7c94e9f4629aedea9b9d..82f89f30750c5d6dfdc06a9ccfe86c59704b6adf 100644 --- a/test/unit/is-serializable-props.test.js +++ b/test/unit/is-serializable-props.test.js @@ -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) + }) })