r1tsuu / payload-enchants

Payload 3.0 enchantment packages
MIT License
132 stars 8 forks source link

fix(translator): prevent duplicated IDs when translating nested array items #70

Closed lynndylanhurley closed 3 months ago

lynndylanhurley commented 3 months ago

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

r1tsuu commented 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.

r1tsuu commented 3 months ago

I'll merge it and release now, but feel free to post here for review or if you have any considerations

lynndylanhurley commented 3 months ago

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.