Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not clear headers when switching between tabs #3552

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-hornets-kiss.md
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

Do not clear default headers when switching between tabs
3 changes: 2 additions & 1 deletion packages/graphiql-react/src/editor/context.tsx
Expand Up @@ -360,13 +360,14 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
headerEditor,
responseEditor,
});
const { onTabChange, defaultHeaders, children } = props;
const setEditorValues = useSetEditorValues({
queryEditor,
variableEditor,
headerEditor,
responseEditor,
defaultHeaders,
});
const { onTabChange, defaultHeaders, children } = props;

const addTab = useCallback<EditorContextType['addTab']>(() => {
setTabState(current => {
Expand Down
8 changes: 6 additions & 2 deletions packages/graphiql-react/src/editor/tabs.ts
Expand Up @@ -258,11 +258,13 @@ export function useSetEditorValues({
variableEditor,
headerEditor,
responseEditor,
defaultHeaders,
}: {
queryEditor: CodeMirrorEditorWithOperationFacts | null;
variableEditor: CodeMirrorEditor | null;
headerEditor: CodeMirrorEditor | null;
responseEditor: CodeMirrorEditor | null;
defaultHeaders?: string;
}) {
return useCallback(
({
Expand All @@ -278,10 +280,12 @@ export function useSetEditorValues({
}) => {
queryEditor?.setValue(query ?? '');
variableEditor?.setValue(variables ?? '');
headerEditor?.setValue(headers ?? '');
if (headerEditor && (headers?.length || defaultHeaders?.length)) {
headerEditor.setValue(headers ?? defaultHeaders ?? '');
}
responseEditor?.setValue(response ?? '');
},
[headerEditor, queryEditor, responseEditor, variableEditor],
[headerEditor, queryEditor, responseEditor, variableEditor, defaultHeaders],
);
}

Expand Down