Repository: cypress-io/cypress
File: packages/app/src/store/studio-store.ts (TypeScript)

Code before:
  canAccessStudioAI: boolean
  showUrlPrompt: boolean
  cloudStudioRequested: boolean
  sessionId?: string
  _isStudioCreatedTest: boolean
  newTestLineNumber?: number
}

function getUrlParams () {
  const url = new URL(window.location.href)
  const hashParams = new URLSearchParams(url.hash)

  const testId = hashParams.get('testId')
  const suiteId = hashParams.get('suiteId')
  const visitUrl = hashParams.get('url')
  const newTestLineNumber = hashParams.get('newTestLineNumber') ? Number(hashParams.get('newTestLineNumber')) : undefined
  const cloudStudioSessionId = hashParams.get('sessionId')

  return { testId, suiteId, url: visitUrl, newTestLineNumber, cloudStudioSessionId }
}

export const useStudioStore = defineStore('studioRecorder', {
  state: (): StudioRecorderState => {
    // try to restore cloudStudioSessionId from URL parameters
    const urlParams = getUrlParams()
    const persistedSessionId = urlParams.cloudStudioSessionId || undefined

    return {
      saveModalIsOpen: false,
      instructionModalIsOpen: false,
      logs: [],
      url: '',
      isLoading: false,
      isActive: false,
      isFailed: false,
      _hasStarted: false,
      _currentId: 1,
      canAccessStudioAI: false,
      showUrlPrompt: true,
      cloudStudioRequested: false,
      sessionId: persistedSessionId,
      newTestLineNumber: undefined,
      _isStudioCreatedTest: false,
    }
  },

  actions: {
    setCloudStudioRequested (cloudStudioRequested: boolean) {
      this.cloudStudioRequested = cloudStudioRequested
    },


Review comment (suggestion):
```suggestion
    const persistedSessionId = urlParams.sessionId || undefined
```

Code after:
  canAccessStudioAI: boolean
  showUrlPrompt: boolean
  cloudStudioRequested: boolean
  sessionId?: string
  _isStudioCreatedTest: boolean
  newTestLineNumber?: number
}

function getUrlParams () {
  const url = new URL(window.location.href)
  const hashParams = new URLSearchParams(url.hash)

  const testId = hashParams.get('testId')
  const suiteId = hashParams.get('suiteId')
  const visitUrl = hashParams.get('url')
  const newTestLineNumber = hashParams.get('newTestLineNumber') ? Number(hashParams.get('newTestLineNumber')) : undefined
  const sessionId = hashParams.get('sessionId')

  return { testId, suiteId, url: visitUrl, newTestLineNumber, sessionId }
}

export const useStudioStore = defineStore('studioRecorder', {
  state: (): StudioRecorderState => {
    // try to restore sessionId from URL parameters
    const urlParams = getUrlParams()
    const persistedSessionId = urlParams.sessionId || undefined

    return {
      saveModalIsOpen: false,
      instructionModalIsOpen: false,
      logs: [],
      url: '',
      isLoading: false,
      isActive: false,
      isFailed: false,
      _hasStarted: false,
      _currentId: 1,
      canAccessStudioAI: false,
      showUrlPrompt: true,
      cloudStudioRequested: false,
      sessionId: persistedSessionId,
      newTestLineNumber: undefined,
      _isStudioCreatedTest: false,
    }
  },

  actions: {
    setCloudStudioRequested (cloudStudioRequested: boolean) {
      this.cloudStudioRequested = cloudStudioRequested
    },