warm.ts
This file
Path
apps/web/src/features/code/warm.ts
29 lines · 1.0 KiB · TypeScript
Last changed by
Merge build/1211-code-browseroscabrielbefore adoptiona6808d3
History of this fileTake it
Merge build/1211-code-browseroscabrielbefore adoptiona6808d3
lines 1–29why, one step back1/**2 * Highlighting a file before its page opens: when a pointer rests on a3 * link to a file, the router fetches the page's data ahead of the click4 * (its intent preload), and the file is then highlighted in the worker5 * pool, so the page draws it at once. Only a file under the highlighting6 * limit is warmed; past it the page draws plain text anyway. Loaded in the7 * browser only, on the first such hover.8 */9import { diffsOptions } from "./pierre.ts";10import { workerPool } from "./pool.tsx";1112/**13 * Highlight `file` in the pool ahead of its page, keyed as the page will14 * draw it; settles once it has (at once for a file not warmed).15 */16export const warmFile = (file: {17 readonly path: string;18 readonly sha: string;19 readonly text?: string | undefined;20}): Promise<void> =>21 "Worker" in globalThis &&22 file.text !== undefined &&23 file.text.length <= diffsOptions.tokenizeMaxLength24 ? workerPool().primeFileHighlightCache({25 cacheKey: file.sha,26 contents: file.text,27 name: file.path,28 })29 : Promise.resolve();