From 3ed9d0fd716da2a1c7d3e3bbcfdbbc9386dd5d1a Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Wed, 5 Aug 2026 09:57:16 +0530 Subject: [PATCH] fix(mobile): prevent Android thread search crash --- .../client-runtime/src/state/threadSearch.test.ts | 13 +++++++++++++ packages/client-runtime/src/state/threadSearch.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/state/threadSearch.test.ts b/packages/client-runtime/src/state/threadSearch.test.ts index 2f1430a51b6b..9e6c682e72d5 100644 --- a/packages/client-runtime/src/state/threadSearch.test.ts +++ b/packages/client-runtime/src/state/threadSearch.test.ts @@ -23,6 +23,19 @@ it("creates stable keys regardless of environment order", () => { ); }); +it("creates keys without array methods unavailable in Hermes", () => { + const descriptor = Object.getOwnPropertyDescriptor(Array.prototype, "toSorted"); + Reflect.deleteProperty(Array.prototype, "toSorted"); + + try { + expect(makeThreadSearchKey([envB, envA], "needle")).toBe('[["env-a","env-b"],"needle"]'); + } finally { + if (descriptor !== undefined) { + Reflect.defineProperty(Array.prototype, "toSorted", descriptor); + } + } +}); + it("encodes scoped thread keys without delimiter collisions", () => { const first = threadSearchMatchKey({ environmentId: EnvironmentId.make("env\u0000thread"), diff --git a/packages/client-runtime/src/state/threadSearch.ts b/packages/client-runtime/src/state/threadSearch.ts index 4011a91cd58c..b71186421ca6 100644 --- a/packages/client-runtime/src/state/threadSearch.ts +++ b/packages/client-runtime/src/state/threadSearch.ts @@ -28,7 +28,7 @@ export function makeThreadSearchKey( query: string, ): string { return JSON.stringify([ - [...environmentIds].toSorted((left, right) => left.localeCompare(right)), + [...environmentIds].sort((left, right) => left.localeCompare(right)), query, ]); }