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
123456789101112131415161718192021222324252627282930/** * Highlighting a file before its page opens: when a pointer rests on a * link to a file, the router fetches the page's data ahead of the click * (its intent preload), and the file is then highlighted in the worker * pool, so the page draws it at once. Only a file under the highlighting * limit is warmed; past it the page draws plain text anyway. Loaded in the * browser only, on the first such hover. */import { diffsOptions } from "./pierre.ts";import { workerPool } from "./pool.tsx";
/** * Highlight `file` in the pool ahead of its page, keyed as the page will * draw it; settles once it has (at once for a file not warmed). */export const warmFile = (file: { readonly path: string; readonly sha: string; readonly text?: string | undefined;}): Promise<void> => "Worker" in globalThis && file.text !== undefined && file.text.length <= diffsOptions.tokenizeMaxLength ? workerPool().primeFileHighlightCache({ cacheKey: file.sha, contents: file.text, name: file.path, }) : Promise.resolve();