File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @graphiql/react ' : patch
3+ ' graphiql ' : patch
4+ ---
5+
6+ fix ` Fixes Uncaught Error: can't access property "offsetNode", hitResult is null ` on Mozilla
Original file line number Diff line number Diff line change 22 "name" : " @graphiql/react" ,
33 "version" : " 0.35.1" ,
44 "sideEffects" : [
5+ " dist/monaco-editor.js" ,
56 " dist/setup-workers/webpack.js" ,
67 " dist/setup-workers/vite.js"
78 ],
Original file line number Diff line number Diff line change 55
66// eslint-disable-next-line @typescript-eslint/no-restricted-imports
77export * from 'monaco-editor' ;
8+ // @ts -expect-error -- no types
9+ import { MouseTargetFactory } from 'monaco-editor/esm/vs/editor/browser/controller/mouseTarget.js' ;
10+
11+ /**
12+ * Patch for Firefox compatibility:
13+ *
14+ * Fixes:
15+ * Uncaught Error: can't access property "offsetNode", hitResult is null
16+ *
17+ * Related issues:
18+ * - https://github.com/graphql/graphiql/issues/4041
19+ * - https://github.com/microsoft/monaco-editor/issues/4679
20+ * - https://github.com/microsoft/monaco-editor/issues/4527
21+ *
22+ * The suggested patch https://github.com/microsoft/monaco-editor/issues/4679#issuecomment-2406284453
23+ * no longer works in Mozilla Firefox
24+ */
25+ if ( navigator . userAgent . includes ( 'Firefox/' ) ) {
26+ const originalFn = MouseTargetFactory . _doHitTestWithCaretPositionFromPoint ;
27+
28+ // @ts -expect-error -- internal override of Monaco method
29+ MouseTargetFactory . _doHitTestWithCaretPositionFromPoint = ( ...args ) => {
30+ const [ ctx , coords ] = args ;
31+ const hitResult = ctx . viewDomNode . ownerDocument . caretPositionFromPoint (
32+ coords . clientX ,
33+ coords . clientY ,
34+ ) ;
35+ if ( hitResult ) {
36+ // Delegate to original function if hitResult is valid
37+ const result = originalFn ( ...args ) ;
38+ return result ;
39+ }
40+ // We must return an object with `type: 0` to avoid the following error:
41+ // Uncaught Error: can't access property "type", result is undefined
42+ return { type : 0 } ;
43+ } ;
44+ }
You can’t perform that action at this time.
0 commit comments