Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,33 @@ describe('sessionRecordingsPlaylistLogic', () => {
})
})

describe('unmounting while a request is in flight', () => {
it('abandons the response instead of reading state that is already gone', async () => {
let requestStarted: () => void = () => {}
const started = new Promise<void>((resolve) => (requestStarted = resolve))
let finishRequest: (response: any) => void = () => {}

jest.spyOn(api.recordings, 'list').mockImplementation(() => {
requestStarted()
return new Promise((resolve) => (finishRequest = resolve))
})
const captureException = jest.spyOn(posthog, 'captureException').mockImplementation()

logic = sessionRecordingsPlaylistLogic({
logicKey: 'unmount-mid-request',
updateSearchParams: true,
})
logic.mount()
await started

logic.unmount()
finishRequest({ results: listOfSessionRecordings, has_next: false })
await new Promise(process.nextTick)

expect(captureException).not.toHaveBeenCalled()
})
})

describe('total filters count', () => {
beforeEach(() => {
logic = sessionRecordingsPlaylistLogic({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,12 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
const response = await api.recordings.list(params)
const loadTimeMs = performance.now() - startTime

actions.reportRecordingsListFetched(loadTimeMs, values.filters, defaultRecordingDurationFilter)

// Bail before touching values: the playlist can unmount mid-request (navigating away,
// switching person tabs), and reading a removed store path throws
breakpoint()

actions.reportRecordingsListFetched(loadTimeMs, values.filters, defaultRecordingDurationFilter)

return {
has_next:
direction === 'newer'
Expand Down
Loading