Skip to content

Commit

Permalink
fix: Change default transport to fetch (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Dec 17, 2024
1 parent a0e73eb commit 2ccc06c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/session-recording.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('Session recording', () => {
[/http:\/\/localhost:\d+\/static\/array.js/, 'script'],
[
/http:\/\/localhost:\d+\/decide\/\?v=3&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
'xmlhttprequest',
'fetch',
],
[/http:\/\/localhost:\d+\/static\/recorder.js\?v=1\.\d\d\d\.\d+/, 'script'],
[/https:\/\/example.com/, 'fetch'],
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('Session recording', () => {
[/http:\/\/localhost:\d+\/static\/array.js/, 'script'],
[
/http:\/\/localhost:\d+\/decide\/\?v=3&ip=1&_=\d+&ver=1\.\d\d\d\.\d+&compression=base64/,
'xmlhttprequest',
'fetch',
],
[/http:\/\/localhost:\d+\/static\/recorder.js\?v=1\.\d\d\d\.\d+/, 'script'],
[/https:\/\/example.com/, 'xmlhttprequest'],
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/featureflags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ describe('featureflags', () => {
expect(instance._send_request).toHaveBeenCalledWith({
url: 'https://us.i.posthog.com/api/early_access_features/?token=random fake token',
method: 'GET',
transport: 'XHR',
transport: 'fetch',
callback: expect.any(Function),
})
expect(instance._send_request).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -507,7 +507,7 @@ describe('featureflags', () => {
url: 'https://us.i.posthog.com/api/early_access_features/?token=random fake token',
method: 'GET',
callback: expect.any(Function),
transport: 'XHR',
transport: 'fetch',
})
expect(instance._send_request).toHaveBeenCalledTimes(1)

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/surveys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('surveys', () => {
expect(instance._send_request).toHaveBeenCalledWith({
url: 'https://us.i.posthog.com/api/surveys/?token=testtoken',
method: 'GET',
transport: 'XHR',
transport: 'fetch',
callback: expect.any(Function),
})
expect(instance._send_request).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('surveys', () => {
expect(instance._send_request).toHaveBeenCalledWith({
url: 'https://us.i.posthog.com/api/surveys/?token=testtoken',
method: 'GET',
transport: 'XHR',
transport: 'fetch',
callback: expect.any(Function),
})
expect(instance._send_request).toHaveBeenCalledTimes(1)
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ export class PostHog {
* // or any way to know the result of the request. PostHog
* // capturing via sendBeacon will not support any event-
* // batching or retry mechanisms.
* api_transport: 'XHR'
* api_transport: 'fetch'
*
* // super properties cookie expiration (in days)
* cookie_expiration: 365
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-featureflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class PostHogFeatureFlags {

if (!existing_early_access_features || force_reload) {
this.instance._send_request({
transport: 'XHR',
transport: 'fetch',
url: this.instance.requestRouter.endpointFor(
'api',
`/api/early_access_features/?token=${this.instance.config.token}`
Expand Down
2 changes: 1 addition & 1 deletion src/posthog-surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class PostHogSurveys {
`/api/surveys/?token=${this.instance.config.token}`
),
method: 'GET',
transport: 'XHR',
transport: 'fetch',
callback: (response) => {
if (response.statusCode !== 200 || !response.json) {
return callback([])
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const request = (_options: RequestOptions) => {
compression: options.compression,
})

const transport = options.transport ?? 'XHR'
const transport = options.transport ?? 'fetch'

const transportMethod =
find(AVAILABLE_TRANSPORTS, (t) => t.transport === transport)?.method ?? AVAILABLE_TRANSPORTS[0].method
Expand Down
2 changes: 1 addition & 1 deletion src/web-experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class WebExperiments {
`/api/web_experiments/?token=${this.instance.config.token}`
),
method: 'GET',
transport: 'XHR',
transport: 'fetch',
callback: (response) => {
if (response.statusCode !== 200 || !response.json) {
return callback([])
Expand Down

0 comments on commit 2ccc06c

Please sign in to comment.