From 56d60920cee902e00a823b0d0d5d3d7ff858e68e Mon Sep 17 00:00:00 2001 From: Omar Diop Date: Tue, 17 Feb 2026 11:23:30 +0100 Subject: [PATCH] fix: build request URL via string concatenation instead of assigning to URL.search Hermes (React Native) exposes URL.search as read-only, causing a runtime error when assigning to it. This replaces the URL.search assignment in eventSource() and getResponse() with string-based URL construction, ensuring compatibility across all JavaScript runtimes. --- src/common.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common.ts b/src/common.ts index 5049211..3494851 100644 --- a/src/common.ts +++ b/src/common.ts @@ -160,11 +160,13 @@ export class Client { req.params = req.params ?? {} req.params['api-key'] = bearer + let eventSourceUrl = remoteURL.toString() if (req.params) { - remoteURL.search = new URLSearchParams(req.params).toString() + const separator = eventSourceUrl.includes('?') ? '&' : '?' + eventSourceUrl = `${eventSourceUrl}${separator}${new URLSearchParams(req.params).toString()}` } - return new EventSource(remoteURL) + return new EventSource(eventSourceUrl) } async getResponse({ @@ -203,11 +205,14 @@ export class Client { requestObject.body = JSON.stringify(body) } + let requestUrl = remoteURL.toString() if (params) { - remoteURL.search = new URLSearchParams(params).toString() + const searchString = new URLSearchParams(params).toString() + const separator = requestUrl.includes('?') ? '&' : '?' + requestUrl = `${requestUrl}${separator}${searchString}` } - const response = await fetch(remoteURL, requestObject) + const response = await fetch(requestUrl, requestObject) if (response.status === 401) { throw new Error( @@ -217,7 +222,7 @@ export class Client { if (response.status === 400) { const errorText = await response.text() throw new Error( - `Bad Request: ${errorText} (path: ${remoteURL.toString()})`, + `Bad Request: ${errorText} (path: ${requestUrl})`, ) } return response