Skip to content

Commit 002f133

Browse files
authored
fix can't access property "jsonDefaults" (#4050)
* try * try * test * test * try monaco-editor/esm/vs/language/json/monaco.contribution.js * fix build * upd * upd
1 parent 9b54581 commit 002f133

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.changeset/yellow-pumas-itch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphiql': patch
3+
'@graphiql/react': patch
4+
---
5+
6+
fix can't access property "jsonDefaults"

packages/graphiql-react/src/components/provider.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import {
2727
import {
2828
DEFAULT_PRETTIFY_QUERY,
2929
DEFAULT_QUERY,
30+
JSON_DIAGNOSTIC_OPTIONS,
3031
STORAGE_KEY,
3132
} from '../constants';
3233
import { getDefaultTabState } from '../utility/tabs';
34+
import { languages } from '../monaco-editor';
3335

3436
interface 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}

packages/graphiql-react/src/constants.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff 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-
139136
export const MONACO_GRAPHQL_DIAGNOSTIC_SETTINGS: DiagnosticSettings = {
140137
validateVariablesJSON: {},
141138
jsonDiagnosticSettings: {

packages/graphiql-react/src/monaco-editor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ import { MouseTargetFactory } from 'monaco-editor/esm/vs/editor/browser/controll
2525
if (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
}

0 commit comments

Comments
 (0)