diff --git a/inspector/app/renderer/components/Session/AttachToSession.js b/inspector/app/renderer/components/Session/AttachToSession.js index 7c97330fd..12280de21 100644 --- a/inspector/app/renderer/components/Session/AttachToSession.js +++ b/inspector/app/renderer/components/Session/AttachToSession.js @@ -23,7 +23,7 @@ export default class AttachToSession extends Component { render () { let {attachSessId, setAttachSessId, runningAppiumSessions, getRunningSessions, t} = this.props; - attachSessId = attachSessId || ''; + attachSessId = attachSessId || undefined; return (
diff --git a/inspector/app/renderer/reducers/Session.js b/inspector/app/renderer/reducers/Session.js index d29782517..8d68b9475 100644 --- a/inspector/app/renderer/reducers/Session.js +++ b/inspector/app/renderer/reducers/Session.js @@ -68,6 +68,19 @@ const INITIAL_STATE = { let nextState; +// returns false if the attachSessId is not present in the runningSessions list +const isAttachSessIdValid = (runningSessions, attachSessId) => { + if (!attachSessId || !runningSessions) { + return false; + } + for (const session of runningSessions) { + if (session.id === attachSessId) { + return true; + } + } + return false; +}; + export default function session (state = INITIAL_STATE, action) { switch (action.type) { case NEW_SESSION_REQUESTED: @@ -237,13 +250,15 @@ export default function session (state = INITIAL_STATE, action) { gettingSessions: true, }; - case GET_SESSIONS_DONE: + case GET_SESSIONS_DONE: { + const attachSessId = isAttachSessIdValid(action.sessions, state.attachSessId) ? state.attachSessId : null; return { ...state, gettingSessions: false, - attachSessId: (action.sessions && action.sessions.length > 0 && !state.attachSessId) ? action.sessions[0].id : state.attachSessId, + attachSessId: (action.sessions && action.sessions.length > 0 && !attachSessId) ? action.sessions[0].id : attachSessId, runningAppiumSessions: action.sessions || [], }; + } case ENABLE_DESIRED_CAPS_EDITOR: return {