From 352f605c58c9421ed55b4b849e7feb8760a210b2 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Thu, 3 Oct 2024 13:12:33 +0200 Subject: [PATCH 1/6] fix: react-native runtime incompatibilities --- packages/sdk/src/FlagResolverClient.ts | 2 +- packages/sdk/src/fetch-util.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/FlagResolverClient.ts b/packages/sdk/src/FlagResolverClient.ts index 50506dce..f37c5e45 100644 --- a/packages/sdk/src/FlagResolverClient.ts +++ b/packages/sdk/src/FlagResolverClient.ts @@ -292,7 +292,7 @@ export function withRequestLogic(fetchImplementation: (request: Request) => Prom // update send-time before sending .modifyRequest(async request => { if (request.method === 'POST') { - const body = JSON.stringify({ ...(await request.json()), sendTime: new Date().toISOString() }); + const body = JSON.stringify({ ...(await request.clone().json()), sendTime: new Date().toISOString() }); return new Request(request, { body }); } return request; diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 9eb4d1b5..3b4d779b 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -233,7 +233,7 @@ export class FetchBuilder { let retryCount = 0; const doRetry = async (e: unknown): Promise => { - request.signal?.throwIfAborted(); + if (request.signal?.aborted ?? false) throw new Error('Request aborted'); // if there are no more attempts we throw the last error if (retryCount >= maxRetries) throw e; From 4e2ac9fc4787cf1fe1f7bd518b18b2132d28f9b1 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Thu, 3 Oct 2024 14:14:28 +0200 Subject: [PATCH 2/6] fixup! fix: react-native runtime incompatibilities --- packages/sdk/src/fetch-util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 3b4d779b..0498ac12 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -233,7 +233,7 @@ export class FetchBuilder { let retryCount = 0; const doRetry = async (e: unknown): Promise => { - if (request.signal?.aborted ?? false) throw new Error('Request aborted'); + if (request.signal?.aborted ?? false) throw new Error('This operation was aborted'); // if there are no more attempts we throw the last error if (retryCount >= maxRetries) throw e; From 3fe49c965e4ebf546c3cdeed06ab4338c54aadc1 Mon Sep 17 00:00:00 2001 From: Nicklas Lundin Date: Thu, 3 Oct 2024 14:47:07 +0200 Subject: [PATCH 3/6] fixup! fixup! fix: react-native runtime incompatibilities --- packages/sdk/src/fetch-util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 0498ac12..09644df0 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -233,7 +233,7 @@ export class FetchBuilder { let retryCount = 0; const doRetry = async (e: unknown): Promise => { - if (request.signal?.aborted ?? false) throw new Error('This operation was aborted'); + if (request.signal?.aborted ?? false) throw request.signal?.reason; // if there are no more attempts we throw the last error if (retryCount >= maxRetries) throw e; @@ -266,7 +266,7 @@ export class FetchBuilder { * @returns the builder itself */ route(match: (url: string) => boolean, fetch: SimpleFetch) { - return this.compose(next => request => match(request.url) ? fetch(request) : next(request)); + return this.compose(next => request => (match(request.url) ? fetch(request) : next(request))); } /** From e61a70cbc4886cb49aee6344530702aa44d12eae Mon Sep 17 00:00:00 2001 From: Nicklas Lundin Date: Thu, 3 Oct 2024 15:03:22 +0200 Subject: [PATCH 4/6] fixup! fixup! fixup! fix: react-native runtime incompatibilities --- packages/sdk/src/fetch-util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 09644df0..588d9de9 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -266,7 +266,7 @@ export class FetchBuilder { * @returns the builder itself */ route(match: (url: string) => boolean, fetch: SimpleFetch) { - return this.compose(next => request => (match(request.url) ? fetch(request) : next(request))); + return this.compose(next => request => match(request.url) ? fetch(request) : next(request)); } /** From cd263af0f95e07962e8467d693df111650a407a6 Mon Sep 17 00:00:00 2001 From: Nicklas Lundin Date: Thu, 3 Oct 2024 16:09:45 +0200 Subject: [PATCH 5/6] fixup! fixup! fixup! fixup! fix: react-native runtime incompatibilities --- packages/sdk/src/fetch-util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 588d9de9..6b29778e 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -233,7 +233,7 @@ export class FetchBuilder { let retryCount = 0; const doRetry = async (e: unknown): Promise => { - if (request.signal?.aborted ?? false) throw request.signal?.reason; + if (request.signal?.aborted ?? false) throw request.signal.reason; // if there are no more attempts we throw the last error if (retryCount >= maxRetries) throw e; @@ -266,7 +266,7 @@ export class FetchBuilder { * @returns the builder itself */ route(match: (url: string) => boolean, fetch: SimpleFetch) { - return this.compose(next => request => match(request.url) ? fetch(request) : next(request)); + return this.compose(next => request => (match(request.url) ? fetch(request) : next(request))); } /** From 4d87d3afa619b7c4a86de97bafbc3c808a2e47aa Mon Sep 17 00:00:00 2001 From: Nicklas Lundin Date: Thu, 3 Oct 2024 16:11:37 +0200 Subject: [PATCH 6/6] fixup! fixup! fixup! fixup! fixup! fix: react-native runtime incompatibilities --- packages/sdk/src/fetch-util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/fetch-util.ts b/packages/sdk/src/fetch-util.ts index 6b29778e..8483d8bc 100644 --- a/packages/sdk/src/fetch-util.ts +++ b/packages/sdk/src/fetch-util.ts @@ -266,7 +266,7 @@ export class FetchBuilder { * @returns the builder itself */ route(match: (url: string) => boolean, fetch: SimpleFetch) { - return this.compose(next => request => (match(request.url) ? fetch(request) : next(request))); + return this.compose(next => request => match(request.url) ? fetch(request) : next(request)); } /**