File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
packages/graphiql-react/src/editor Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @graphiql/react ' : patch
3
+ ' graphiql ' : patch
4
+ ---
5
+
6
+ Solves #2825 , an old bug where new tabs were created on every refresh
7
+
8
+ the bug occurred when:
9
+
10
+ 1 . ` shouldPersistHeaders ` is not set to true
11
+ 2 . ` headers ` or ` defaultHeaders ` are provided as props
12
+ 3 . the user refreshes the browser
Original file line number Diff line number Diff line change @@ -311,6 +311,7 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
311
311
defaultQuery : props . defaultQuery || DEFAULT_QUERY ,
312
312
defaultHeaders : props . defaultHeaders ,
313
313
storage,
314
+ shouldPersistHeaders,
314
315
} ) ;
315
316
storeTabs ( tabState ) ;
316
317
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export function getDefaultTabState({
72
72
query,
73
73
variables,
74
74
storage,
75
+ shouldPersistHeaders,
75
76
} : {
76
77
defaultQuery : string ;
77
78
defaultHeaders ?: string ;
@@ -80,15 +81,23 @@ export function getDefaultTabState({
80
81
query : string | null ;
81
82
variables : string | null ;
82
83
storage : StorageAPI | null ;
84
+ shouldPersistHeaders ?: boolean ;
83
85
} ) {
84
86
const storedState = storage ?. get ( STORAGE_KEY ) ;
85
87
try {
86
88
if ( ! storedState ) {
87
89
throw new Error ( 'Storage for tabs is empty' ) ;
88
90
}
89
91
const parsed = JSON . parse ( storedState ) ;
92
+ // if headers are not persisted, do not derive the hash using default headers state
93
+ // or else you will get new tabs on every refresh
94
+ const headersForHash = shouldPersistHeaders ? headers : undefined ;
90
95
if ( isTabsState ( parsed ) ) {
91
- const expectedHash = hashFromTabContents ( { query, variables, headers } ) ;
96
+ const expectedHash = hashFromTabContents ( {
97
+ query,
98
+ variables,
99
+ headers : headersForHash ,
100
+ } ) ;
92
101
let matchingTabIndex = - 1 ;
93
102
94
103
for ( let index = 0 ; index < parsed . tabs . length ; index ++ ) {
You can’t perform that action at this time.
0 commit comments