Skip to content

Commit f513d73

Browse files
committed
fix invalid links breaking render
1 parent e8f2d2b commit f513d73

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: packages/render/src/renderAsync.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ export const renderAsync = async (
117117
}
118118
}
119119

120+
// Add onerror attribute to all <link rel="stylesheet"> tags.
121+
// This ensures that if a stylesheet link fails (due to an invalid URL or CORS issues),
122+
// it gets removed, so that the iframe content can still load.
123+
extractedHeadContents = extractedHeadContents.replace(
124+
/<link([^>]*rel=["']stylesheet["'][^>]*)>/gi,
125+
(match, p1) => {
126+
if (match.includes('onerror=')) return match;
127+
return `<link${p1} onerror="console.error('Failed to load stylesheet:', this.href); this.onerror=null;this.remove();">`;
128+
}
129+
);
130+
120131
const document = dedent(`
121132
<!DOCTYPE html>
122133
<html>
@@ -147,11 +158,6 @@ export const renderAsync = async (
147158
scaleFactor,
148159
timestamp: new Date().toISOString()
149160
});
150-
151-
// const htmlElement = document.querySelector("html");
152-
// if (htmlElement) {
153-
// htmlElement.style.transform = "scale(" + scaleFactor + ") translateX(" + horizontalPadding + "px)";
154-
// }
155161
} catch (err) {
156162
console.error("Error in scaleToFit:", err);
157163
}

0 commit comments

Comments
 (0)