Skip to content

Commit 2d3d95d

Browse files
committed
Merge origin/main into posthog-token-efficiency-data
2 parents 7171d08 + 2460649 commit 2d3d95d

35 files changed

Lines changed: 2483 additions & 791 deletions

‎apps/marketing/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"@t3tools/shared": "workspace:*",
14-
"astro": "^7.0.3"
14+
"astro": "^7.0.3",
15+
"sharp": "0.34.5"
1516
},
1617
"devDependencies": {
1718
"@astrojs/check": "^0.9.7",
File renamed without changes.

‎apps/marketing/src/layouts/Layout.astro‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import { Image } from "astro:assets";
3+
import appIcon from "../assets/icon.webp";
24
import {
35
ANDROID_PLAY_STORE_URL,
46
GITHUB_REPOSITORY_URL,
@@ -67,7 +69,17 @@ const {
6769
<footer class="footer">
6870
<div class="footer-inner">
6971
<div class="footer-brand">
70-
<img src="/icon.webp" alt="" />
72+
<Image
73+
src={appIcon}
74+
alt=""
75+
width={20}
76+
height={20}
77+
densities={[1, 2, 3]}
78+
format="webp"
79+
quality={90}
80+
loading="lazy"
81+
decoding="async"
82+
/>
7183
<span>&copy; {new Date().getFullYear()} T3 Tools Inc · MIT licensed</span>
7284
</div>
7385
<div class="footer-links">

‎apps/marketing/src/pages/index.astro‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
import { getImage } from "astro:assets";
3+
import desktopScreenshot from "../assets/app-desktop.webp";
24
import Layout from "../layouts/Layout.astro";
35
import {
46
ANDROID_PLAY_STORE_URL,
@@ -8,6 +10,13 @@ import {
810
} from "../lib/site";
911
import { tweets } from "../lib/tweets";
1012
13+
const screenshot = await getImage({
14+
src: desktopScreenshot,
15+
widths: [864, 1180, 1728, 2360],
16+
format: "webp",
17+
quality: 90,
18+
});
19+
1120
const desktopEndorsementRows = [
1221
tweets.filter((_, index) => index % 2 === 0),
1322
tweets.filter((_, index) => index % 2 === 1),
@@ -80,14 +89,23 @@ const mobileEndorsementRows = [
8089
<div data-rise style="--d:520ms">
8190
<div class="hero-preview">
8291
<figure class="hero-screenshot-frame">
83-
<img
84-
src="/app-desktop.webp"
85-
alt="T3 Code with a settled thread beside its pull request diff"
86-
width="2880"
87-
height="1800"
88-
loading="eager"
89-
decoding="async"
90-
/>
92+
<picture>
93+
<!-- Match the hidden mobile layout without requesting a screenshot. -->
94+
<source
95+
media="(max-width: 820px)"
96+
srcset="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
97+
/>
98+
<img
99+
src={desktopScreenshot.src}
100+
srcset={`${screenshot.srcSet.attribute}, ${desktopScreenshot.src} ${desktopScreenshot.width}w`}
101+
sizes="(max-width: 960px) min(864px, calc(100vw - 20px)), min(1180px, calc(100vw - 60px))"
102+
alt="T3 Code with a settled thread beside its pull request diff"
103+
width={desktopScreenshot.width}
104+
height={desktopScreenshot.height}
105+
loading="eager"
106+
decoding="async"
107+
/>
108+
</picture>
91109
</figure>
92110
</div>
93111
</div>

‎apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.ts‎

Lines changed: 151 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22

33
import type { NativeReviewDiffRow } from "./nativeReviewDiffSurface";
44
import type { NativeReviewDiffFile } from "./nativeReviewDiffTypes";
5-
import { highlightNativeReviewDiffVisibleRows } from "./nativeReviewDiffHighlighter";
5+
import {
6+
highlightNativeReviewDiffVisibleRows,
7+
streamNativeReviewDiffTokens,
8+
type NativeReviewDiffTokenChunk,
9+
} from "./nativeReviewDiffHighlighter";
10+
11+
const tokenization = vi.hoisted(() => ({
12+
calls: [] as string[],
13+
afterCall: undefined as (() => void) | undefined,
14+
}));
15+
16+
vi.mock("@shikijs/core", async (importOriginal) => {
17+
const original = await importOriginal<typeof import("@shikijs/core")>();
18+
return {
19+
...original,
20+
createHighlighterCore: async (...args: Parameters<typeof original.createHighlighterCore>) => {
21+
const highlighter = await original.createHighlighterCore(...args);
22+
return {
23+
...highlighter,
24+
codeToTokensBase: (...input: Parameters<typeof highlighter.codeToTokensBase>) => {
25+
tokenization.calls.push(input[0]);
26+
const result = highlighter.codeToTokensBase(...input);
27+
tokenization.afterCall?.();
28+
return result;
29+
},
30+
};
31+
},
32+
};
33+
});
34+
35+
// Exercise the native entry path without requiring an iOS or Android runtime.
36+
vi.mock("react-native-shiki-engine", async () => {
37+
const { createJavaScriptRegexEngine } = await import("@shikijs/engine-javascript");
38+
return { isNativeEngineAvailable: () => true, createNativeEngine: createJavaScriptRegexEngine };
39+
});
40+
41+
afterEach(() => {
42+
tokenization.calls = [];
43+
tokenization.afterCall = undefined;
44+
});
645

746
const TYPESCRIPT_FILE: NativeReviewDiffFile = {
847
id: "file-1",
@@ -187,3 +226,113 @@ describe("highlightNativeReviewDiffVisibleRows", () => {
187226
);
188227
});
189228
});
229+
230+
describe.each(["native", "javascript"] as const)("%s highlighting budgets", (engine) => {
231+
const highlightRows = (rows: ReadonlyArray<NativeReviewDiffRow>, signal?: AbortSignal) =>
232+
highlightNativeReviewDiffVisibleRows({
233+
rows,
234+
files: [TYPESCRIPT_FILE],
235+
scheme: "dark",
236+
engine,
237+
firstRowIndex: 0,
238+
lastRowIndex: rows.length - 1,
239+
overscanRows: 0,
240+
signal,
241+
});
242+
243+
const line = (id: number, content: string) =>
244+
makeLine({
245+
id: `line-${id}`,
246+
content,
247+
change: "add",
248+
oldLineNumber: null,
249+
newLineNumber: id,
250+
});
251+
252+
it("still highlights a line at the length limit", async () => {
253+
const content = `// ${"x".repeat(997)}`;
254+
const result = await highlightRows([line(1, content)]);
255+
256+
expect(tokenization.calls).toEqual([content]);
257+
expect(result.tokensByRowId["line-1"]?.some((token) => token.color !== null)).toBe(true);
258+
});
259+
260+
it("keeps long lines and unknown following syntax plain until the next hunk", async () => {
261+
const longLine = `${"x".repeat(1_001)} /*`;
262+
const rows = [
263+
line(1, "export const before = 1;"),
264+
line(2, longLine),
265+
{ kind: "comment", id: "note", commentText: "Check this", fileId: TYPESCRIPT_FILE.id },
266+
line(3, "inside the comment */"),
267+
makeHunk("next-hunk"),
268+
line(100, "export const after = 2;"),
269+
] satisfies ReadonlyArray<NativeReviewDiffRow>;
270+
const result = await highlightRows(rows);
271+
272+
expect(result.engine).toBe(engine);
273+
expect(Object.keys(result.tokensByRowId)).toEqual(["line-1", "line-2", "line-3", "line-100"]);
274+
expect(result.tokensByRowId["line-2"]).toEqual([
275+
{ content: longLine, color: null, fontStyle: null },
276+
]);
277+
expect(result.tokensByRowId["line-3"]).toEqual([
278+
{ content: "inside the comment */", color: null, fontStyle: null },
279+
]);
280+
expect(result.tokensByRowId["line-1"]?.some((token) => token.color !== null)).toBe(true);
281+
expect(result.tokensByRowId["line-100"]?.some((token) => token.color !== null)).toBe(true);
282+
expect(tokenization.calls.some((code) => code.includes(longLine))).toBe(false);
283+
});
284+
285+
it("preserves multiline grammar and row mapping across character-limited batches", async () => {
286+
const opening = line(1, "const message = `open");
287+
const body = Array.from({ length: 40 }, (_, index) => line(index + 2, "inside ".repeat(45)));
288+
const closing = line(42, "closed`; ");
289+
const trailing = line(43, "export const after = 2;");
290+
const result = await highlightRows([opening, ...body, closing, trailing]);
291+
const calls = [...tokenization.calls];
292+
const expected = await highlightRows([
293+
opening,
294+
{ ...closing, newLineNumber: 2 },
295+
{ ...trailing, newLineNumber: 3 },
296+
]);
297+
298+
expect(calls.length).toBeGreaterThan(1);
299+
expect(calls.every((code) => code.length <= 8_000)).toBe(true);
300+
expect(result.rowCount).toBe(43);
301+
for (const row of [opening, ...body, closing, trailing]) {
302+
expect(result.tokensByRowId[row.id]?.map((token) => token.content).join("")).toBe(
303+
row.content,
304+
);
305+
}
306+
expect(result.tokensByRowId[closing.id]).toEqual(expected.tokensByRowId[closing.id]);
307+
expect(result.tokensByRowId[trailing.id]).toEqual(expected.tokensByRowId[trailing.id]);
308+
});
309+
310+
it("stops before later batches and publishes no partial result after cancellation", async () => {
311+
const controller = new AbortController();
312+
tokenization.afterCall = () => controller.abort();
313+
const rows = Array.from({ length: 30 }, (_, index) => line(index + 1, `// ${"x".repeat(400)}`));
314+
315+
const result = await highlightRows(rows, controller.signal);
316+
317+
expect(tokenization.calls).toHaveLength(1);
318+
expect(result.rowCount).toBe(0);
319+
expect(result.tokensByRowId).toEqual({});
320+
});
321+
322+
it("applies the same long-line guard to streamed token chunks", async () => {
323+
const content = "x".repeat(10_000);
324+
const chunks: NativeReviewDiffTokenChunk[] = [];
325+
326+
await streamNativeReviewDiffTokens({
327+
rows: [line(1, content)],
328+
files: [TYPESCRIPT_FILE],
329+
scheme: "dark",
330+
engine,
331+
onChunk: (chunk) => chunks.push(chunk),
332+
});
333+
334+
expect(chunks).toHaveLength(1);
335+
expect(chunks[0]?.tokensByRowId["line-1"]).toEqual([{ content, color: null, fontStyle: null }]);
336+
expect(tokenization.calls).toHaveLength(0);
337+
});
338+
});

0 commit comments

Comments
 (0)