File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed
packages/graphiql-react/src Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' graphiql ' : patch
3+ ' @graphiql/react ' : patch
4+ ---
5+
6+ fix can't access property "jsonDefaults"
Original file line number Diff line number Diff line change @@ -27,9 +27,11 @@ import {
2727import {
2828 DEFAULT_PRETTIFY_QUERY ,
2929 DEFAULT_QUERY ,
30+ JSON_DIAGNOSTIC_OPTIONS ,
3031 STORAGE_KEY ,
3132} from '../constants' ;
3233import { getDefaultTabState } from '../utility/tabs' ;
34+ import { languages } from '../monaco-editor' ;
3335
3436interface InnerGraphiQLProviderProps
3537 extends EditorProps ,
@@ -328,6 +330,16 @@ const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({
328330 } ;
329331 } , [ ] ) ;
330332
333+ useEffect ( ( ) => {
334+ /**
335+ * Set diagnostics options for JSON
336+ *
337+ * Setting it on mount fix Uncaught TypeError: Cannot read properties of undefined (reading 'jsonDefaults')
338+ * @see https://github.com/graphql/graphiql/pull/4042#issuecomment-3017167375
339+ */
340+ languages . json . jsonDefaults . setDiagnosticsOptions ( JSON_DIAGNOSTIC_OPTIONS ) ;
341+ } , [ ] ) ;
342+
331343 return (
332344 < GraphiQLContext . Provider value = { storeRef } >
333345 { children }
Original file line number Diff line number Diff line change @@ -126,16 +126,13 @@ export const URI_NAME = {
126126} as const ;
127127
128128// set these early on so that initial variables with comments don't flash an error
129- const JSON_DIAGNOSTIC_OPTIONS : languages . json . DiagnosticsOptions = {
129+ export const JSON_DIAGNOSTIC_OPTIONS : languages . json . DiagnosticsOptions = {
130130 // Fixes Comments are not permitted in JSON.(521)
131131 allowComments : true ,
132132 // Fixes Trailing comma json(519)
133133 trailingCommas : 'ignore' ,
134134} ;
135135
136- // Set diagnostics options for JSON
137- languages . json . jsonDefaults . setDiagnosticsOptions ( JSON_DIAGNOSTIC_OPTIONS ) ;
138-
139136export const MONACO_GRAPHQL_DIAGNOSTIC_SETTINGS : DiagnosticSettings = {
140137 validateVariablesJSON : { } ,
141138 jsonDiagnosticSettings : {
Original file line number Diff line number Diff line change @@ -25,15 +25,16 @@ import { MouseTargetFactory } from 'monaco-editor/esm/vs/editor/browser/controll
2525if ( navigator . userAgent . includes ( 'Firefox/' ) ) {
2626 const originalFn = MouseTargetFactory . _doHitTestWithCaretPositionFromPoint ;
2727
28- // @ts -expect-error -- internal override of Monaco method
29- MouseTargetFactory . _doHitTestWithCaretPositionFromPoint = ( ...args ) => {
28+ MouseTargetFactory . _doHitTestWithCaretPositionFromPoint = (
29+ ...args : any [ ]
30+ ) => {
3031 const [ ctx , coords ] = args ;
3132 const hitResult = ctx . viewDomNode . ownerDocument . caretPositionFromPoint (
3233 coords . clientX ,
3334 coords . clientY ,
3435 ) ;
3536 if ( hitResult ) {
36- // Delegate to original function if hitResult is valid
37+ // Delegate to the original function if hitResult is valid
3738 const result = originalFn ( ...args ) ;
3839 return result ;
3940 }
You can’t perform that action at this time.
0 commit comments