Skip to content

Commit 6554697

Browse files
committed
fix(mobile): prevent Hermes crashes when opening threads
1 parent 211618f commit 6554697

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { derivePendingRequests } from "@t3tools/client-runtime/pending-requests";
2-
import { describe, expect, it } from "vite-plus/test";
2+
import { beforeEach, describe, expect, it } from "vite-plus/test";
33

44
import {
55
ApprovalRequestId,
@@ -27,6 +27,21 @@ import {
2727
type WorkLogEntry,
2828
} from "./threadActivity";
2929

30+
// Match Hermes: these ES2023 array methods are absent on mobile.
31+
beforeEach(() => {
32+
const methods = ["toSorted", "toReversed"] as const;
33+
const descriptors = methods.map((method) =>
34+
Object.getOwnPropertyDescriptor(Array.prototype, method),
35+
);
36+
for (const method of methods) Reflect.deleteProperty(Array.prototype, method);
37+
return () => {
38+
for (const [index, method] of methods.entries()) {
39+
const descriptor = descriptors[index];
40+
if (descriptor) Reflect.defineProperty(Array.prototype, method, descriptor);
41+
}
42+
};
43+
});
44+
3045
const singleSelectQuestion = {
3146
id: "runtime",
3247
header: "Runtime",

‎packages/client-runtime/src/work-log/presentation.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,9 @@ export function omitSupersededLifecycleMarkers<T>(
658658
}
659659
}
660660

661-
return reversedEntries.toReversed();
661+
// Hermes lacks toReversed; this array is local, so reversing it cannot mutate the input.
662+
// oxlint-disable-next-line unicorn/no-array-reverse
663+
return reversedEntries.reverse();
662664
}
663665

664666
export function toolGroupSummaryKind(

‎packages/client-runtime/src/work-log/userInput.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ function questionFingerprint(
2727
questions: ReadonlyArray<unknown>,
2828
): string | undefined {
2929
const texts = questions.map((question) => (typeof question === "string" ? question.trim() : ""));
30+
// Sort the fresh array in place because Hermes does not provide toSorted.
3031
return texts.length > 0 && texts.every(Boolean)
31-
? JSON.stringify([turnId, texts.toSorted()])
32+
? JSON.stringify([turnId, texts.sort()])
3233
: undefined;
3334
}
3435

0 commit comments

Comments
 (0)