Skip to content
TypeScript

fix(mobile): thread links show their thread's title (#26485)

Julius Marminge976a23161d3e
diff --git a/packages/shared/src/threadLinks.test.ts b/packages/shared/src/threadLinks.test.ts
index 82d981f5982..aa1c02fd4be 100644
--- a/packages/shared/src/threadLinks.test.ts
+++ b/packages/shared/src/threadLinks.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from "vite-plus/test";
+import { describe, expect, it, vi } from "vite-plus/test";
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
import {
@@ -143,6 +143,22 @@ describe("thread links", () => {
).toEqual([ref("there", "t1"), ref("local", "t%3A2"), ref("local", "t:2")]);
});
+ it("lists a message's thread links on runtimes whose matchAll omits named groups, such as Hermes", () => {
+ const matchAll = String.prototype.matchAll;
+ using _hermes = vi.spyOn(String.prototype, "matchAll").mockImplementation(function (
+ this: string,
+ regexp: RegExp,
+ ) {
+ return matchAll.call(this, regexp).map((match) => {
+ delete match.groups;
+ return match;
+ });
+ });
+ expect(threadLinkRefs("<t3-thread://v2/local/t1> [a](t3-thread://v2/there/t2)", local)).toEqual(
+ [ref("local", "t1"), ref("there", "t2")],
+ );
+ });
+
it("writes a titleless autolink that opens that exact thread", () => {
const link = formatThreadLink(ref("env-1", "thread:delegated-task:mcp%3A1"));
expect(link).toBe("<t3-thread://v2/env-1/thread:delegated-task:mcp%3A1>");
diff --git a/packages/shared/src/threadLinks.ts b/packages/shared/src/threadLinks.ts
index a71fe4489d6..aceb87635c2 100644
--- a/packages/shared/src/threadLinks.ts
+++ b/packages/shared/src/threadLinks.ts
@@ -97,7 +97,9 @@ export function threadLinkRefs(
messageEnvironmentId: EnvironmentId,
): ReadonlyArray<ScopedThreadRef> {
const refs = new Map<string, ScopedThreadRef>();
- for (const match of markdown.matchAll(THREAD_LINK_OUTSIDE_CODE)) {
+ // Hermes' matchAll yields matches without `groups`; exec keeps them.
+ const pattern = new RegExp(THREAD_LINK_OUTSIDE_CODE);
+ for (let match = pattern.exec(markdown); match !== null; match = pattern.exec(markdown)) {
const href = match.groups?.href ?? match.groups?.autolink;
const link = href === undefined ? null : parseThreadLinkHref(href);
if (link === null) continue;