Skip to content

Commit 34158e0

Browse files
committed
Improve relative path detection. See #253
1 parent ee974ed commit 34158e0

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/api/preCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function preCache(root = document, options = {}) {
103103
.map(k => String(k).split('__')[0])
104104
.filter(Boolean)
105105
)
106-
await ensureFontsReady(families, 2)
106+
await ensureFontsReady(families, 3)
107107
}
108108

109109
await embedCustomFonts({

src/modules/fonts.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ function rewriteRelativeUrls(cssText, baseHref) {
222222
// Supports both @import url("...") and @import "..."
223223
const IMPORT_ANY_RE = /@import\s+(?:url\(\s*(['"]?)([^)"']+)\1\s*\)|(['"])([^"']+)\3)([^;]*);/g
224224

225+
const MAX_IMPORT_DEPTH = 4
226+
225227
/**
226228
* Flattens @import recursively and rewrites relative urls at each level
227229
* using that sheet's base href. Uses snapFetch (with proxy) on purpose
@@ -234,7 +236,6 @@ async function inlineImportsAndRewrite(cssText, ownerHref, useProxy) {
234236
if (!cssText) return cssText
235237

236238
const visited = new Set()
237-
const MAX_IMPORT_DEPTH = 10
238239

239240
function normalizeUrl(u, base) {
240241
try { return new URL(u, base || location.href).href } catch { return u }
@@ -258,7 +259,7 @@ async function inlineImportsAndRewrite(cssText, ownerHref, useProxy) {
258259

259260
if (visited.has(absUrl)) {
260261
console.warn(`[snapDOM] Skipping circular @import: ${absUrl}`)
261-
continue // skip re-including this import
262+
continue
262263
}
263264
visited.add(absUrl)
264265

@@ -504,7 +505,6 @@ async function collectFacesFromSheet(sheet, baseHref, emitFace, ctx) {
504505
const normalizeUrl = (u, base) => {
505506
try { return new URL(u, base || location.href).href } catch { return u }
506507
}
507-
const MAX_IMPORT_DEPTH = 10
508508

509509
for (const rule of rules) {
510510
if (rule.type === CSSRule.IMPORT_RULE && rule.styleSheet) {
@@ -961,7 +961,6 @@ export async function ensureFontsReady(families, warmupRepetitions = 2) {
961961

962962
document.body.appendChild(container)
963963
// Force layout
964-
965964
container.offsetWidth
966965
document.body.removeChild(container)
967966
}

0 commit comments

Comments
 (0)