fix: admin validation broken when json is still an object (#20894)

This commit is contained in:
Rémi de Juvigny 2024-07-29 13:57:24 +02:00 committed by GitHub
parent 533533434d
commit 2eab9a4f1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { forwardRef, memo } from 'react';
import * as React from 'react';
import {
JSONInput as JSONInputImpl,
@ -12,7 +12,7 @@ import { useField } from '../Form';
import { InputProps } from './types';
const JsonInput = forwardRef<JSONInputRef, InputProps>(
const JsonInput = React.forwardRef<JSONInputRef, InputProps>(
({ name, required, label, hint, labelAction, ...props }, ref) => {
const field = useField(name);
const fieldRef = useFocusInputField(name);
@ -43,6 +43,6 @@ const JsonInput = forwardRef<JSONInputRef, InputProps>(
}
);
const MemoizedJsonInput = memo(JsonInput);
const MemoizedJsonInput = React.memo(JsonInput);
export { MemoizedJsonInput as JsonInput };

View File

@ -181,6 +181,16 @@ const createAttributeSchema = (
return true;
}
// If the value was created via content API and wasn't changed, then it's still an object
if (typeof value === 'object') {
try {
JSON.stringify(value);
return true;
} catch (err) {
return false;
}
}
try {
JSON.parse(value);