Skip to content

Commit 976a231

Browse files
fix(mobile): thread links show their thread's title (#26485)
1 parent 965291e commit 976a231

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎packages/shared/src/threadLinks.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { describe, expect, it, vi } from "vite-plus/test";
22
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
33

44
import {
@@ -143,6 +143,22 @@ describe("thread links", () => {
143143
).toEqual([ref("there", "t1"), ref("local", "t%3A2"), ref("local", "t:2")]);
144144
});
145145

146+
it("lists a message's thread links on runtimes whose matchAll omits named groups, such as Hermes", () => {
147+
const matchAll = String.prototype.matchAll;
148+
using _hermes = vi.spyOn(String.prototype, "matchAll").mockImplementation(function (
149+
this: string,
150+
regexp: RegExp,
151+
) {
152+
return matchAll.call(this, regexp).map((match) => {
153+
delete match.groups;
154+
return match;
155+
});
156+
});
157+
expect(threadLinkRefs("<t3-thread://v2/local/t1> [a](t3-thread://v2/there/t2)", local)).toEqual(
158+
[ref("local", "t1"), ref("there", "t2")],
159+
);
160+
});
161+
146162
it("writes a titleless autolink that opens that exact thread", () => {
147163
const link = formatThreadLink(ref("env-1", "thread:delegated-task:mcp%3A1"));
148164
expect(link).toBe("<t3-thread://v2/env-1/thread:delegated-task:mcp%3A1>");

‎packages/shared/src/threadLinks.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export function threadLinkRefs(
9797
messageEnvironmentId: EnvironmentId,
9898
): ReadonlyArray<ScopedThreadRef> {
9999
const refs = new Map<string, ScopedThreadRef>();
100-
for (const match of markdown.matchAll(THREAD_LINK_OUTSIDE_CODE)) {
100+
// Hermes' matchAll yields matches without `groups`; exec keeps them.
101+
const pattern = new RegExp(THREAD_LINK_OUTSIDE_CODE);
102+
for (let match = pattern.exec(markdown); match !== null; match = pattern.exec(markdown)) {
101103
const href = match.groups?.href ?? match.groups?.autolink;
102104
const link = href === undefined ? null : parseThreadLinkHref(href);
103105
if (link === null) continue;

0 commit comments

Comments
 (0)