Skip to content

Commit

Permalink
fix: cannot read body twice (#19750)
Browse files Browse the repository at this point in the history
* fix: cannot read body twice

* only read it once no matter what

* fix tests but yucky

* nicer

* does this mean backend checks won't incorrectly run

* comment
  • Loading branch information
pauldambra authored Jan 15, 2024
1 parent f09c76e commit f236e25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ jobs:
# the dependencies more clear if we separated the backend/frontend
# code completely
# really we should ignore ee/frontend/** but dorny doesn't support that
# - '!ee/frontend/**'
# including the negated rule appears to work
# but makes it always match because the checked file always isn't `ee/frontend/**` 🙈
- 'ee/**/*'
- '!ee/frontend/**'
- 'posthog/**/*'
- 'bin/*.py'
- requirements.txt
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,17 +1555,18 @@ const api = {
.withQueryString(toParams({ source: 'blob', blob_key: blobKey, version: '2' }))
.getResponse()

const contentBuffer = new Uint8Array(await response.arrayBuffer())
try {
const textLines = await response.text()
const textDecoder = new TextDecoder()
const textLines = textDecoder.decode(contentBuffer)

if (textLines) {
return textLines.split('\n')
}
} catch (e) {
// Must be gzipped
// we assume it is gzipped, swallow the error, and carry on below
}

const contentBuffer = new Uint8Array(await response.arrayBuffer())
return strFromU8(decompressSync(contentBuffer)).trim().split('\n')
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ describe('sessionRecordingDataLogic', () => {
})
resumeKeaLoadersErrors()
})

it('fetch metadata success and snapshots error', async () => {
silenceKeaLoadersErrors()
// Unmount and remount the logic to trigger fetching the data again after the mock change
Expand Down
6 changes: 6 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import 'whatwg-fetch'
import 'jest-canvas-mock'

import { TextEncoder, TextDecoder } from 'util'
// Jest/JSDom don't know about TextEncoder but the browsers we support do
// https://github.com/jsdom/jsdom/issues/2524
global.TextDecoder = TextDecoder
global.TextEncoder = TextEncoder

window.scrollTo = jest.fn()
window.matchMedia = jest.fn(
() => ({ matches: false, addListener: jest.fn(), removeListener: jest.fn() } as MediaQueryList)
Expand Down

0 comments on commit f236e25

Please sign in to comment.