diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts index 46a79b70acd2..fb85ce1e1cc3 100644 --- a/apps/mobile/src/lib/threadActivity.test.ts +++ b/apps/mobile/src/lib/threadActivity.test.ts @@ -1,5 +1,5 @@ import { derivePendingRequests } from "@t3tools/client-runtime/pending-requests"; -import { describe, expect, it } from "vite-plus/test"; +import { beforeEach, describe, expect, it } from "vite-plus/test"; import { ApprovalRequestId, @@ -27,6 +27,21 @@ import { type WorkLogEntry, } from "./threadActivity"; +// Match Hermes: these ES2023 array methods are absent on mobile. +beforeEach(() => { + const methods = ["toSorted", "toReversed"] as const; + const descriptors = methods.map((method) => + Object.getOwnPropertyDescriptor(Array.prototype, method), + ); + for (const method of methods) Reflect.deleteProperty(Array.prototype, method); + return () => { + for (const [index, method] of methods.entries()) { + const descriptor = descriptors[index]; + if (descriptor) Reflect.defineProperty(Array.prototype, method, descriptor); + } + }; +}); + const singleSelectQuestion = { id: "runtime", header: "Runtime", diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.ts index 8d62bb0794ca..bfb04eda3247 100644 --- a/packages/client-runtime/src/work-log/presentation.ts +++ b/packages/client-runtime/src/work-log/presentation.ts @@ -658,7 +658,9 @@ export function omitSupersededLifecycleMarkers( } } - return reversedEntries.toReversed(); + // Hermes lacks toReversed; this array is local, so reversing it cannot mutate the input. + // oxlint-disable-next-line unicorn/no-array-reverse + return reversedEntries.reverse(); } export function toolGroupSummaryKind( diff --git a/packages/client-runtime/src/work-log/userInput.ts b/packages/client-runtime/src/work-log/userInput.ts index 355083c04836..18dea7dd83c2 100644 --- a/packages/client-runtime/src/work-log/userInput.ts +++ b/packages/client-runtime/src/work-log/userInput.ts @@ -27,8 +27,9 @@ function questionFingerprint( questions: ReadonlyArray, ): string | undefined { const texts = questions.map((question) => (typeof question === "string" ? question.trim() : "")); + // Sort the fresh array in place because Hermes does not provide toSorted. return texts.length > 0 && texts.every(Boolean) - ? JSON.stringify([turnId, texts.toSorted()]) + ? JSON.stringify([turnId, texts.sort()]) : undefined; }