Skip to content

Commit 37d99a5

Browse files
committed
fix: reuse preCache image dataURLs in the capture path
inlineImages now reads/writes cache.image, so preCache's image prefetch is actually used instead of re-fetching every image.
1 parent 2e938a4 commit 37d99a5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/modules/images.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { snapFetch } from './snapFetch.js'
8+
import { cache } from '../core/cache.js'
89

910
const XLINK_NS = 'http://www.w3.org/1999/xlink'
1011

@@ -59,9 +60,21 @@ export async function inlineImages(clone, options = {}) {
5960
const src = img.src || ''
6061
if (!src) return
6162

63+
// Reuse a dataURL prefetched by preCache (keyed by the same resolved src) so the capture
64+
// path doesn't re-fetch it. snapFetch doesn't cache successes, so without this the prefetch
65+
// bought nothing.
66+
const cached = cache.image?.get(src)
67+
if (cached) {
68+
img.src = cached
69+
if (!img.width) img.width = img.naturalWidth || 100
70+
if (!img.height) img.height = img.naturalHeight || 100
71+
return
72+
}
73+
6274
const r = await snapFetch(src, { as: 'dataURL', useProxy: options.useProxy })
6375
if (r.ok && typeof r.data === 'string' && r.data.startsWith('data:')) {
6476
// Success path: inline DataURL and ensure dimensions for layout fidelity
77+
cache.image?.set(src, r.data)
6578
img.src = r.data
6679
if (!img.width) img.width = img.naturalWidth || 100
6780
if (!img.height) img.height = img.naturalHeight || 100

0 commit comments

Comments
 (0)