| 42 | const isUpdatingRef = useRef(false); |
| 43 | |
| 44 | const validateContent = (content: string) => { |
| 45 | if (!content.trim()) { |
| 46 | setIsValid(true); |
| 47 | setError(undefined); |
| 48 | onValidate?.(true); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if (language === 'json') { |
| 53 | try { |
| 54 | JSON.parse(content); |
| 55 | setIsValid(true); |
| 56 | setError(undefined); |
| 57 | onValidate?.(true); |
| 58 | } catch (e) { |
| 59 | setIsValid(false); |
| 60 | const errorMsg = |
| 61 | e instanceof Error ? e.message : 'Invalid JSON syntax'; |
| 62 | setError(errorMsg); |
| 63 | onValidate?.(false, errorMsg); |
| 64 | } |
| 65 | } else if (language === 'javascript') { |
| 66 | // No frontend validation for JavaScript - validation happens in tRPC |
| 67 | setIsValid(true); |
| 68 | setError(undefined); |
| 69 | onValidate?.(true); |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | // Create editor once on mount |
| 74 | useEffect(() => { |