Skip to content

Commit d9e0cd3

Browse files
authored
fix: 'oldValue' must be a string error when viewing version diffs in postgres (#10313)
Fixes #10068 We were accidentally not catching that in postgres IDs return as strings but the react diff viewer expects a string
1 parent abb51b9 commit d9e0cd3

File tree

1 file changed

+8
-4
lines changed
  • packages/next/src/views/Version/RenderFieldsToDiff/fields/Relationship

1 file changed

+8
-4
lines changed

packages/next/src/views/Version/RenderFieldsToDiff/fields/Relationship/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ const generateLabelFromValue = (
3434
}
3535

3636
let relatedDoc: RelationshipValue
37-
let valueToReturn = '' as any
37+
let valueToReturn: RelationshipValue | string = ''
3838

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

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

@@ -76,19 +77,22 @@ const generateLabelFromValue = (
7677
valueToReturn = relatedDoc
7778
}
7879

79-
if (typeof valueToReturn === 'object' && titleFieldIsLocalized) {
80+
if (typeof valueToReturn === 'object' && titleFieldIsLocalized && valueToReturn?.[locale]) {
8081
valueToReturn = valueToReturn[locale]
8182
}
8283
} else if (relatedDoc) {
8384
// Handle non-polymorphic `hasMany` relationships or fallback
8485
if (typeof relatedDoc?.id !== 'undefined') {
85-
valueToReturn = relatedDoc.id
86+
valueToReturn = String(relatedDoc.id)
8687
} else {
8788
valueToReturn = relatedDoc
8889
}
8990
}
9091

91-
if (typeof valueToReturn === 'object' && valueToReturn !== null) {
92+
if (
93+
(valueToReturn && typeof valueToReturn === 'object' && valueToReturn !== null) ||
94+
typeof valueToReturn !== 'string'
95+
) {
9296
valueToReturn = JSON.stringify(valueToReturn)
9397
}
9498

0 commit comments

Comments
 (0)