mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-10 18:35:17 +00:00
Large read-only files bypassed the editor's virtualization and eagerly mounted every highlighted token, which could stall the renderer for seconds and consume gigabytes of memory. Route source previews through bounded platform renderers and reject reads above their display budgets before accumulation.
18 lines
658 B
TypeScript
18 lines
658 B
TypeScript
export const SOURCE_PRESENTATION_BUDGETS = {
|
|
web: { highlighted: 10 * 1024 * 1024, plain: 50 * 1024 * 1024 },
|
|
native: { highlighted: 1024 * 1024, plain: 10 * 1024 * 1024 },
|
|
} as const;
|
|
|
|
export type SourcePresentation = "highlighted" | "plain" | "unsupported";
|
|
export type SourcePlatform = keyof typeof SOURCE_PRESENTATION_BUDGETS;
|
|
|
|
export function selectSourcePresentation(input: {
|
|
size: number;
|
|
platform: SourcePlatform;
|
|
}): SourcePresentation {
|
|
const budgets = SOURCE_PRESENTATION_BUDGETS[input.platform];
|
|
if (input.size <= budgets.highlighted) return "highlighted";
|
|
if (input.size <= budgets.plain) return "plain";
|
|
return "unsupported";
|
|
}
|