fix: ensure leavesFirst option works correctly in traverseFields utility (#11219)

We have to ensure the arguments are handled wherever we push to the callback stack, not when we execute the callback stack.
This commit is contained in:
Alessio Gravili
2025-02-16 19:14:46 -07:00
committed by GitHub
parent 513ba636af
commit 6b9d81a746
4 changed files with 138 additions and 30 deletions

View File

@@ -1,3 +1,4 @@
import { dequal } from 'dequal/lite'
import { type Block, type BlockSlug, type Config, traverseFields } from 'payload'
export const autoDedupeBlocksPlugin =
@@ -68,7 +69,9 @@ export const deduplicateBlock = ({
// Check if the fields are the same
const jsonExistingBlock = JSON.stringify(existingBlock, null, 2)
const jsonBlockToDeduplicate = JSON.stringify(dedupedBlock, null, 2)
if (jsonExistingBlock !== jsonBlockToDeduplicate) {
// dequal check of blocks with functions removed (through JSON.stringify+JSON.parse). We cannot check the strings,
// as the order of keys in the object is not guaranteed, yet it doesn't matter for the block fields.
if (!dequal(JSON.parse(jsonExistingBlock), JSON.parse(jsonBlockToDeduplicate))) {
console.error('Block with the same slug but different fields found', {
slug: dedupedBlock.slug,
existingBlock: jsonExistingBlock,

View File

@@ -86,5 +86,8 @@
"ts-essentials": "10.0.3",
"typescript": "5.7.3",
"uuid": "10.0.0"
},
"dependencies": {
"dequal": "2.0.3"
}
}