You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code Editor - add documentation how to use JSON Schemas #10647
It is not super straight forward to get the beforeMount call to cooperate with yaml parsing and many people using our code editor are using it for parsing/editing yaml files.
The process to load a JSON Schema in the code editor (used for both JSON and YAML autocompletion) looks like the following:
create a beforeMount callback that will receive the monaco instance and use the configureMonacoYaml function from the monaco-yaml package to set the desired JSON Schema.
Capture the output of the configureMonacoYaml function into a Ref so we can dispose of it when the component is unmounted, otherwise the yaml worker is not released and a duplicated autocompletion appears in addition to the memory leak
Provide an empty useEffect that returns a dispose function, so we ensure it executes when leaving the component.
For reference:
Setting the schema
consteditorProps=useRef({beforeMount: (monaco)=>{if(currentSchema){// Keep the output of the `configureMonacoYaml` functionconstmonacoYamlHandler=configureMonacoYaml(monaco,{enableSchemaRequest: true,hover: true,completion: true,validate: true,format: true,schemas: [{schema: '<your schema goes here>',uri: '<your schema URI>',fileMatch: ['*'],},],});/** Capturing the monacoYamlHandlerRef so we can dispose it when unmounting this component */monacoYamlHandlerRef.current=monacoYamlHandler;}},});
Disposing the workers
useEffect(()=>{/** * This useEffect acts as an unmount hook for the CodeEditor component * It disposes the monacoYamlHandlerRef.current when the component is unmounted */return()=>{monacoYamlHandlerRef.current?.dispose();};},[]);
Activity
lordrip commentedon Jul 12, 2024
The process to load a JSON Schema in the code editor (used for both JSON and YAML autocompletion) looks like the following:
beforeMountcallback that will receive themonacoinstance and use theconfigureMonacoYamlfunction from themonaco-yamlpackage to set the desired JSON Schema.configureMonacoYamlfunction into aRefso we can dispose of it when the component is unmounted, otherwise the yaml worker is not released and a duplicated autocompletion appears in addition to the memory leakuseEffectthat returns a dispose function, so we ensure it executes when leaving the component.For reference:
Setting the schema
Disposing the workers
Setting the editorProps
github-actions commentedon Sep 11, 2024
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.