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

Code before:
  fileDetails?: FileDetails
  absoluteFile?: string
  runnableTitle?: string
  _previousMouseEvent?: {
    element: Element
    selector: string
  }
  _currentId: number

  canAccessStudioAI: boolean
  showUrlPrompt: boolean
  cloudStudioRequested: boolean
  cloudStudioSessionId?: 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('cloudStudioSessionId')

  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,
      cloudStudioSessionId: persistedSessionId,
      newTestLineNumber: undefined,

Review comment (suggestion):
Since we are already in the context of `studio`, suggest renaming the url parameter `sessionId`.

Code after:
  fileDetails?: FileDetails
  absoluteFile?: string
  runnableTitle?: string
  _previousMouseEvent?: {
    element: Element
    selector: string
  }
  _currentId: number

  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,