From 9822210e13cee8961f90f9975dfa23c0c009fec2 Mon Sep 17 00:00:00 2001 From: Apoorva Agrawal Date: Fri, 26 Dec 2025 23:58:21 +0530 Subject: [PATCH 1/2] fix: resolve 2020-12 schema loading error in Monaco --- app/components/CodeEditor/CodeEditor.tsx | 14 ++++++ lib/schemas.ts | 30 ++++++++++++ package.json | 2 +- pnpm-lock.yaml | 58 ++++++++++++++++-------- 4 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 lib/schemas.ts diff --git a/app/components/CodeEditor/CodeEditor.tsx b/app/components/CodeEditor/CodeEditor.tsx index 32870c3..03e11fb 100644 --- a/app/components/CodeEditor/CodeEditor.tsx +++ b/app/components/CodeEditor/CodeEditor.tsx @@ -15,6 +15,7 @@ import { sendGAEvent } from "@next/third-parties/google"; import { CodeFile, OutputResult } from "@/lib/types"; import { OutputReducerAction } from "@/lib/reducers"; import CertificateButton from "../CertificateButton/CertificateButton"; +import { DRAFT_2020_12_METASCHEMA_FLAT } from "@/lib/schemas"; // Custom hook for editor theme setup const useEditorTheme = (monaco: Monaco, colorMode: "dark" | "light") => { @@ -211,6 +212,19 @@ export default function CodeEditor({ const handleEditorMount = (editor: any, monaco: Monaco) => { setMonaco(monaco); + monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ + validate: true, + allowComments: true, + enableSchemaRequest: true, + schemas: [ + { + uri: "https://json-schema.org/draft/2020-12/schema", + fileMatch: ["*"], + schema: DRAFT_2020_12_METASCHEMA_FLAT, + }, + ], + }); + editorRef.current = editor; editorStore.setEditor(editor); editorStore.setMonaco(monaco); diff --git a/lib/schemas.ts b/lib/schemas.ts new file mode 100644 index 0000000..c7f6d19 --- /dev/null +++ b/lib/schemas.ts @@ -0,0 +1,30 @@ +export const DRAFT_2020_12_METASCHEMA_FLAT = { + $schema: "https://json-schema.org/draft/2020-12/schema", + $id: "https://json-schema.org/draft/2020-12/schema", + title: "Core vocabulary meta-schema (Flattened for Monaco)", + type: ["object", "boolean"], + properties: { + $id: { type: "string", format: "uri-reference" }, + $schema: { type: "string", format: "uri" }, + $ref: { type: "string", format: "uri-reference" }, + $anchor: { type: "string", pattern: "^[A-Za-z_][-A-Za-z0-0_:]*$" }, + $defs: { + type: "object", + additionalProperties: { type: ["object", "boolean"] }, + }, + $vocabulary: { + type: "object", + additionalProperties: { type: "boolean" }, + }, + type: { + anyOf: [ + { enum: ["array", "boolean", "integer", "null", "number", "object", "string"] }, + { + type: "array", + items: { enum: ["array", "boolean", "integer", "null", "number", "object", "string"] }, + uniqueItems: true, + }, + ], + }, + }, +}; \ No newline at end of file diff --git a/package.json b/package.json index 74fa25b..cf1b576 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@hyperjump/json-schema": "^1.9.2", "@mdx-js/loader": "^3.0.1", "@mdx-js/react": "^3.0.1", - "@monaco-editor/react": "^4.6.0", + "@monaco-editor/react": "^4.7.0", "@next/mdx": "^14.2.3", "@next/third-parties": "^14.2.5", "@types/mdx": "^2.0.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ad8a83..38084f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,8 +39,8 @@ importers: specifier: ^3.0.1 version: 3.0.1(@types/react@18.3.3)(react@18.3.1) '@monaco-editor/react': - specifier: ^4.6.0 - version: 4.6.0(monaco-editor@0.50.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^4.7.0 + version: 4.7.0(monaco-editor@0.55.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@next/mdx': specifier: ^14.2.3 version: 14.2.5(@mdx-js/loader@3.0.1(webpack@5.93.0))(@mdx-js/react@3.0.1(@types/react@18.3.3)(react@18.3.1)) @@ -1150,17 +1150,15 @@ packages: '@types/react': '>=16' react: '>=16' - '@monaco-editor/loader@1.4.0': - resolution: {integrity: sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==} - peerDependencies: - monaco-editor: '>= 0.21.0 < 1' + '@monaco-editor/loader@1.7.0': + resolution: {integrity: sha512-gIwR1HrJrrx+vfyOhYmCZ0/JcWqG5kbfG7+d3f/C1LXk2EvzAbHSg3MQ5lO2sMlo9izoAZ04shohfKLVT6crVA==} - '@monaco-editor/react@4.6.0': - resolution: {integrity: sha512-RFkU9/i7cN2bsq/iTkurMWOEErmYcY6JiQI3Jn+WeR/FGISH8JbHERjpS9oRuSOPvDMJI0Z8nJeKkbOs9sBYQw==} + '@monaco-editor/react@4.7.0': + resolution: {integrity: sha512-cyzXQCtO47ydzxpQtCGSQGOC8Gk3ZUeBXFAxD+CWXYFo5OqZyZUonFl0DwUlTyAfRHntBfw2p3w4s9R6oe1eCA==} peerDependencies: monaco-editor: '>= 0.25.0 < 1' - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 '@next/env@14.2.10': resolution: {integrity: sha512-dZIu93Bf5LUtluBXIv4woQw2cZVZ2DJTjax5/5DOs3lzEOeKLy7GxRSr4caK9/SCPdaW6bCgpye6+n4Dh9oJPw==} @@ -1462,6 +1460,9 @@ packages: '@types/react@18.3.3': resolution: {integrity: sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==} + '@types/trusted-types@2.0.7': + resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==} + '@types/unist@2.0.10': resolution: {integrity: sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==} @@ -2029,6 +2030,9 @@ packages: dom-accessibility-api@0.5.16: resolution: {integrity: sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==} + dompurify@3.2.7: + resolution: {integrity: sha512-WhL/YuveyGXJaerVlMYGWhvQswa7myDG17P7Vu65EWC05o8vfeNbvNf4d/BOvH99+ZW+LlQsc1GDKMa1vNK6dw==} + eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -2916,6 +2920,11 @@ packages: resolution: {integrity: sha512-o5vL7aDWatOTX8LzaS1WMoaoxIiLRQJuIKKe2wAw6IeULDHaqbiqiggmx+pKvZDb1Sj+pE46Sn1T7lCqfFtg1Q==} engines: {node: '>=16'} + marked@14.0.0: + resolution: {integrity: sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==} + engines: {node: '>= 18'} + hasBin: true + mdast-util-definitions@5.1.2: resolution: {integrity: sha512-8SVPMuHqlPME/z3gqVwWY4zVXn8lqKv/pAhC57FuJ40ImXyBpmO5ukh98zB2v7Blql2FiHjHv9LVztSIqjY+MA==} @@ -3191,8 +3200,8 @@ packages: mlly@1.7.1: resolution: {integrity: sha512-rrVRZRELyQzrIUAVMHxP97kv+G786pHmOKzuFII8zDYahFBS7qnHh2AlYSl1GAHhaMPCz6/oHjVMcfFYgFYHgA==} - monaco-editor@0.50.0: - resolution: {integrity: sha512-8CclLCmrRRh+sul7C08BmPBP3P8wVWfBHomsTcndxg5NRCEPfu/mc2AGU8k37ajjDVXcXFc12ORAMUkmk+lkFA==} + monaco-editor@0.55.1: + resolution: {integrity: sha512-jz4x+TJNFHwHtwuV9vA9rMujcZRb0CEilTEwG2rRSpe/A7Jdkuj8xPKttCgOh+v/lkHy7HsZ64oj+q3xoAFl9A==} mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -5584,15 +5593,14 @@ snapshots: '@types/react': 18.3.3 react: 18.3.1 - '@monaco-editor/loader@1.4.0(monaco-editor@0.50.0)': + '@monaco-editor/loader@1.7.0': dependencies: - monaco-editor: 0.50.0 state-local: 1.0.7 - '@monaco-editor/react@4.6.0(monaco-editor@0.50.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@monaco-editor/react@4.7.0(monaco-editor@0.55.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@monaco-editor/loader': 1.4.0(monaco-editor@0.50.0) - monaco-editor: 0.50.0 + '@monaco-editor/loader': 1.7.0 + monaco-editor: 0.55.1 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) @@ -5847,6 +5855,9 @@ snapshots: '@types/prop-types': 15.7.12 csstype: 3.1.3 + '@types/trusted-types@2.0.7': + optional: true + '@types/unist@2.0.10': {} '@types/unist@3.0.2': {} @@ -6513,6 +6524,10 @@ snapshots: dom-accessibility-api@0.5.16: {} + dompurify@3.2.7: + optionalDependencies: + '@types/trusted-types': 2.0.7 + eastasianwidth@0.2.0: {} electron-to-chromium@1.5.4: {} @@ -7635,6 +7650,8 @@ snapshots: markdown-extensions@2.0.0: {} + marked@14.0.0: {} + mdast-util-definitions@5.1.2: dependencies: '@types/mdast': 3.0.15 @@ -8305,7 +8322,10 @@ snapshots: pkg-types: 1.1.3 ufo: 1.5.4 - monaco-editor@0.50.0: {} + monaco-editor@0.55.1: + dependencies: + dompurify: 3.2.7 + marked: 14.0.0 mri@1.2.0: {} @@ -9618,4 +9638,4 @@ snapshots: '@types/react': 18.3.3 react: 18.3.1 - zwitch@2.0.4: {} \ No newline at end of file + zwitch@2.0.4: {} From 3edfbd4d1ffd7cd753f46abcecba98635bb80e63 Mon Sep 17 00:00:00 2001 From: Apoorva Agrawal Date: Thu, 1 Jan 2026 14:12:56 +0530 Subject: [PATCH 2/2] Fix: disable Monaco schema resolution and rely on validator --- app/components/CodeEditor/CodeEditor.tsx | 18 +++++--------- lib/schemas.ts | 30 ------------------------ 2 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 lib/schemas.ts diff --git a/app/components/CodeEditor/CodeEditor.tsx b/app/components/CodeEditor/CodeEditor.tsx index 03e11fb..d4312a0 100644 --- a/app/components/CodeEditor/CodeEditor.tsx +++ b/app/components/CodeEditor/CodeEditor.tsx @@ -15,7 +15,6 @@ import { sendGAEvent } from "@next/third-parties/google"; import { CodeFile, OutputResult } from "@/lib/types"; import { OutputReducerAction } from "@/lib/reducers"; import CertificateButton from "../CertificateButton/CertificateButton"; -import { DRAFT_2020_12_METASCHEMA_FLAT } from "@/lib/schemas"; // Custom hook for editor theme setup const useEditorTheme = (monaco: Monaco, colorMode: "dark" | "light") => { @@ -213,17 +212,12 @@ export default function CodeEditor({ setMonaco(monaco); monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ - validate: true, - allowComments: true, - enableSchemaRequest: true, - schemas: [ - { - uri: "https://json-schema.org/draft/2020-12/schema", - fileMatch: ["*"], - schema: DRAFT_2020_12_METASCHEMA_FLAT, - }, - ], - }); + validate: true, + allowComments: true, + enableSchemaRequest: false, + schemaValidation: "ignore", + schemaRequest: "ignore", + }); editorRef.current = editor; editorStore.setEditor(editor); diff --git a/lib/schemas.ts b/lib/schemas.ts deleted file mode 100644 index c7f6d19..0000000 --- a/lib/schemas.ts +++ /dev/null @@ -1,30 +0,0 @@ -export const DRAFT_2020_12_METASCHEMA_FLAT = { - $schema: "https://json-schema.org/draft/2020-12/schema", - $id: "https://json-schema.org/draft/2020-12/schema", - title: "Core vocabulary meta-schema (Flattened for Monaco)", - type: ["object", "boolean"], - properties: { - $id: { type: "string", format: "uri-reference" }, - $schema: { type: "string", format: "uri" }, - $ref: { type: "string", format: "uri-reference" }, - $anchor: { type: "string", pattern: "^[A-Za-z_][-A-Za-z0-0_:]*$" }, - $defs: { - type: "object", - additionalProperties: { type: ["object", "boolean"] }, - }, - $vocabulary: { - type: "object", - additionalProperties: { type: "boolean" }, - }, - type: { - anyOf: [ - { enum: ["array", "boolean", "integer", "null", "number", "object", "string"] }, - { - type: "array", - items: { enum: ["array", "boolean", "integer", "null", "number", "object", "string"] }, - uniqueItems: true, - }, - ], - }, - }, -}; \ No newline at end of file