Skip to content

Commit

Permalink
Rollup merge of #123784 - GuillaumeGomez:replace-document-write, r=no…
Browse files Browse the repository at this point in the history
…triddle

Replace `document.write` with `document.head.insertAdjacent`

From [this comment](https://github.com/rust-lang/rust/pull/123706/files#r1559864981), using `document.write` is strongly discouraged (explained on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/write)).

I think in this case it was mostly ok but better be on the safe side.

r? `@notriddle`
  • Loading branch information
matthiaskrgr committed Apr 11, 2024
2 parents da75aaf + 510bfc2 commit 0ab8cc1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<meta name="description" content="{{page.description}}"> {# #}
<title>{{page.title}}</title> {# #}
<script>if(window.location.protocol!=="file:") {# Hack to skip preloading fonts locally - see #98769 #}
for(f of "{{files.source_serif_4_regular}},{{files.fira_sans_regular}},{{files.fira_sans_medium}},{{files.source_code_pro_regular}},{{files.source_code_pro_semibold}}".split(",")) {# #}
document.write(`<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}${f}">`) {# #}
document.head.insertAdjacentHTML("beforeend","{{files.source_serif_4_regular}},{{files.fira_sans_regular}},{{files.fira_sans_medium}},{{files.source_code_pro_regular}},{{files.source_code_pro_semibold}}".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="{{static_root_path|safe}}${f}">`).join("")) {# #}
</script> {# #}
<link rel="stylesheet" {#+ #}
href="{{static_root_path|safe}}{{files.normalize_css}}"> {# #}
Expand Down

0 comments on commit 0ab8cc1

Please sign in to comment.