diff --git a/packages/graphql-playground-react/src/components/Playground/QueryEditor.tsx b/packages/graphql-playground-react/src/components/Playground/QueryEditor.tsx index 928d3807a..227d271ce 100644 --- a/packages/graphql-playground-react/src/components/Playground/QueryEditor.tsx +++ b/packages/graphql-playground-react/src/components/Playground/QueryEditor.tsx @@ -184,6 +184,7 @@ export class QueryEditor extends React.PureComponent { componentWillReceiveProps(nextProps) { if (this.props.sessionId !== nextProps.sessionId) { this.closeCompletion() + this.editor.focus() } } diff --git a/packages/graphql-playground-react/src/state/sessions/reducers.ts b/packages/graphql-playground-react/src/state/sessions/reducers.ts index b8505728a..813851807 100644 --- a/packages/graphql-playground-react/src/state/sessions/reducers.ts +++ b/packages/graphql-playground-react/src/state/sessions/reducers.ts @@ -367,7 +367,9 @@ const reducer = handleActions( .set('sessionCount', newState.sessions.size) }, NEW_SESSION: (state, { payload: { reuseHeaders, endpoint } }) => { - let session = makeSession(endpoint || state.sessions.first().endpoint) + let session = makeSession( + endpoint || state.sessions.first().endpoint, + ).set('query', '') if (reuseHeaders) { const selectedSessionId = getSelectedSessionId(state) const currentSession = state.sessions.get(selectedSessionId) @@ -521,10 +523,9 @@ function closeTab(state, sessionId) { // if there is only one session, delete it and replace it by a new one // and keep the endpoint & headers of the last one if (length === 1) { - const newSession = makeSession(session.endpoint).set( - 'headers', - session.headers, - ) + const newSession = makeSession(session.endpoint) + .set('headers', session.headers) + .set('query', '') newState = newState.set('selectedSessionId', newSession.id) return newState.setIn(['sessions', newSession.id], newSession) }