Skip to content

Commit

Permalink
fix: 'oldValue' must be a string error when viewing version diffs in …
Browse files Browse the repository at this point in the history
…postgres (#10313)

Fixes #10068

We were accidentally not catching that in postgres IDs return as strings
but the react diff viewer expects a string
  • Loading branch information
paulpopus authored Jan 2, 2025
1 parent abb51b9 commit d9e0cd3
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const generateLabelFromValue = (
}

let relatedDoc: RelationshipValue
let valueToReturn = '' as any
let valueToReturn: RelationshipValue | string = ''

const relationTo = 'relationTo' in field ? field.relationTo : undefined

if (value === null || typeof value === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- We want to return a string specifilly for null and undefined
return String(value)
}

Expand Down Expand Up @@ -76,19 +77,22 @@ const generateLabelFromValue = (
valueToReturn = relatedDoc
}

if (typeof valueToReturn === 'object' && titleFieldIsLocalized) {
if (typeof valueToReturn === 'object' && titleFieldIsLocalized && valueToReturn?.[locale]) {
valueToReturn = valueToReturn[locale]
}
} else if (relatedDoc) {
// Handle non-polymorphic `hasMany` relationships or fallback
if (typeof relatedDoc?.id !== 'undefined') {
valueToReturn = relatedDoc.id
valueToReturn = String(relatedDoc.id)
} else {
valueToReturn = relatedDoc
}
}

if (typeof valueToReturn === 'object' && valueToReturn !== null) {
if (
(valueToReturn && typeof valueToReturn === 'object' && valueToReturn !== null) ||
typeof valueToReturn !== 'string'
) {
valueToReturn = JSON.stringify(valueToReturn)
}

Expand Down

0 comments on commit d9e0cd3

Please sign in to comment.