Closed lynndylanhurley closed 3 months ago
Hi @lynndylanhurley
I don't think we should make another data traversing here, also:
function objNeedsNewId(val: unknown): val is { id: string } {
return (
typeof val === 'object' &&
val !== null &&
'id' in val &&
!('blockType' in val) &&
typeof val.id === 'string'
);
}
I see your what you want to do, but it doesn't necessary mean that we look up only for an array items here, it could be JSON for example. It also could break localized blocks.
Instead i fixed the handling of localized blocks / arrays in "traverseFields" and added changes from your PR https://github.com/r1tsuu/payload-enchants/pull/69 as it seems like without this the issue still persists.
I'll merge it and release now, but feel free to post here for review or if you have any considerations
thanks @r1tsuu , I agree that my approach was heavy handed and problematic.
I had initially tried doing this in the traverseFields
method, but the changed IDs weren't persisting and I couldn't figure out why. I'll pull down your latest update and test.
This resolves an issue where nested array items are copied along with their IDs from the source locale, which causes a postgres DB error due to non-unique IDs.
Fixes #65