Skip to content

Commit 2a46972

Browse files
Import directly from leaf modules in graphiql-react to fix Rollup chunk cycles (#4272)
## Summary `@graphiql/react` builds with `preserveModules: true`. Eight files import from barrels (`./components`, `./utility`, `./stores`) for symbols whose defining module also depends on those barrels. Rollup can't split the resulting cycle into chunks cleanly, and emits 18 warnings like: > Export `useGraphiQLActions` of module `src/components/provider.tsx` was reexported through module `src/components/index.ts` while both modules are dependencies of each other … will likely lead to broken execution order. Rollup's own hint is to import from the leaf module directly. Doing that drops the warning count from 18 to 0. Same runtime behavior.
1 parent a1fb763 commit 2a46972

8 files changed

Lines changed: 12 additions & 27 deletions

File tree

packages/graphiql-react/src/components/operation-editor.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import { FC, useEffect, useRef } from 'react';
88
import { useMonaco } from '../stores';
99
import { useGraphiQL, useGraphiQLActions } from './provider';
1010
import {
11-
debounce,
1211
getOrCreateModel,
1312
createEditor,
1413
onEditorContainerKeyDown,
15-
pick,
16-
cleanupDisposables,
17-
cn,
18-
Uri,
19-
Range,
20-
} from '../utility';
14+
} from '../utility/create-editor';
15+
import { debounce, pick, cleanupDisposables, cn, Uri, Range } from '../utility';
2116
import type { MonacoEditor, EditorProps, SchemaReference } from '../types';
2217
import {
2318
KEY_BINDINGS,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ import {
1111
import { create, useStore, UseBoundStore, StoreApi } from 'zustand';
1212
import { useShallow } from 'zustand/shallow';
1313
import { StorageAPI } from '@graphiql/toolkit';
14+
import { createEditorSlice, type EditorProps } from '../stores/editor';
1415
import {
15-
createEditorSlice,
1616
createExecutionSlice,
1717
createPluginSlice,
1818
createSchemaSlice,
1919
createThemeSlice,
2020
createStorageSlice,
21-
EditorProps,
2221
ExecutionProps,
2322
PluginProps,
2423
SchemaProps,

packages/graphiql-react/src/components/request-headers-editor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import { URI_NAME, KEY_BINDINGS, STORAGE_KEY } from '../constants';
55
import {
66
getOrCreateModel,
77
createEditor,
8-
useChangeHandler,
98
onEditorContainerKeyDown,
10-
pick,
11-
cleanupDisposables,
12-
cn,
13-
} from '../utility';
9+
} from '../utility/create-editor';
10+
import { useChangeHandler, pick, cleanupDisposables, cn } from '../utility';
1411
import { useMonaco } from '../stores';
1512

1613
interface RequestHeadersEditorProps extends EditorProps {

packages/graphiql-react/src/components/response-editor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import {
77
getOrCreateModel,
88
createEditor,
99
onEditorContainerKeyDown,
10-
pick,
11-
cleanupDisposables,
12-
cn,
13-
Range,
14-
} from '../utility';
10+
} from '../utility/create-editor';
11+
import { pick, cleanupDisposables, cn, Range } from '../utility';
1512
import { KEY_BINDINGS, URI_NAME } from '../constants';
1613
import type { EditorProps } from '../types';
1714
import type * as monaco from 'monaco-editor';

packages/graphiql-react/src/components/variables-editor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import { KEY_BINDINGS, STORAGE_KEY, URI_NAME } from '../constants';
55
import {
66
getOrCreateModel,
77
createEditor,
8-
useChangeHandler,
98
onEditorContainerKeyDown,
10-
cleanupDisposables,
11-
cn,
12-
pick,
13-
} from '../utility';
9+
} from '../utility/create-editor';
10+
import { useChangeHandler, cleanupDisposables, cn, pick } from '../utility';
1411
import { useMonaco } from '../stores';
1512

1613
interface VariablesEditorProps extends EditorProps {

packages/graphiql-react/src/deprecated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-deprecated */
22

3-
import { useGraphiQL, useGraphiQLActions } from './components';
3+
import { useGraphiQL, useGraphiQLActions } from './components/provider';
44
import { pick } from './utility';
55
import type { MonacoEditor } from './types';
66

packages/graphiql-react/src/utility/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useRef, useState } from 'react';
22
import { debounce } from './debounce';
33
import type * as monaco from 'monaco-editor';
4-
import { useGraphiQL, useGraphiQLActions } from '../components';
4+
import { useGraphiQL, useGraphiQLActions } from '../components/provider';
55

66
export function useChangeHandler(
77
callback: ((value: string) => void) | undefined,

packages/graphiql-react/src/utility/resize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef, useState } from 'react';
22
import { debounce } from './debounce';
3-
import { useGraphiQL } from '../components';
3+
import { useGraphiQL } from '../components/provider';
44

55
type ResizableElement = 'first' | 'second';
66

0 commit comments

Comments
 (0)