Start one shared highlight request unless the cache or an in-flight promise already has it.
( file: DiffFile, theme: AppTheme, cacheKey = buildCacheKey(theme, file), )
| 102 | |
| 103 | /** Start one shared highlight request unless the cache or an in-flight promise already has it. */ |
| 104 | function ensureHighlightedDiffLoaded( |
| 105 | file: DiffFile, |
| 106 | theme: AppTheme, |
| 107 | cacheKey = buildCacheKey(theme, file), |
| 108 | ) { |
| 109 | const cached = SHARED_HIGHLIGHTED_DIFF_CACHE.get(cacheKey); |
| 110 | if (cached) { |
| 111 | return Promise.resolve(cached); |
| 112 | } |
| 113 | |
| 114 | const existing = SHARED_HIGHLIGHT_PROMISES.get(cacheKey); |
| 115 | if (existing) { |
| 116 | return existing; |
| 117 | } |
| 118 | |
| 119 | let pending: Promise<HighlightedDiffCode>; |
| 120 | pending = loadHighlightedDiff(file, theme) |
| 121 | .then((nextHighlighted) => { |
| 122 | commitHighlightResult(cacheKey, pending, nextHighlighted); |
| 123 | return nextHighlighted; |
| 124 | }) |
| 125 | .catch(() => { |
| 126 | const fallback = { |
| 127 | deletionLines: [], |
| 128 | additionLines: [], |
| 129 | } satisfies HighlightedDiffCode; |
| 130 | commitHighlightResult(cacheKey, pending, fallback); |
| 131 | return fallback; |
| 132 | }); |
| 133 | |
| 134 | SHARED_HIGHLIGHT_PROMISES.set(cacheKey, pending); |
| 135 | return pending; |
| 136 | } |
| 137 | |
| 138 | /** Queue syntax highlighting for one file without mounting its diff rows first. */ |
| 139 | export function prefetchHighlightedDiff({ file, theme }: { file: DiffFile; theme: AppTheme }) { |
no test coverage detected