Skip to content

Commit

Permalink
fix: improve render blocking assets in dev mode (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Jul 22, 2024
1 parent ea0f00f commit 4136b09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-suits-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Improve handling of render blocking assets in dev mode.
18 changes: 6 additions & 12 deletions src/render-assets-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,16 @@ function renderAssets(slot) {
// To avoid FOUC we will hide the page until all of these modules are loaded.
const { preload } = entry;
if (preload) {
let sep = "";
html += \`<script\${this.___viteInjectAttrs}>((root=document.documentElement)=>{\`;
html += "root.style.visibility='hidden';";
html += "document.currentScript.remove();";
html += "Promise.allSettled([";
html += \`<script class=marko-vite-preload blocking=render type=module\${this.___viteInjectAttrs}>\`;
for (const id of preload) {
html += \`\${sep}import(\${JSON.stringify(base + id)})\`;
sep = ",";
html += \`import \${JSON.stringify(base + id)};\`;
}
html += "]).then(()=>{";
html += "root.style.visibility='';";
html += "document.querySelectorAll('.marko-vite-preload').forEach((el) => el.remove());";
html += "document.documentElement.style.visibility='';";
html +=
"if(root.getAttribute('style')==='')root.removeAttribute('style')";
html += "})})()</script>";
"if(document.documentElement.getAttribute('style')==='')document.documentElement.removeAttribute('style');";
html += "</script><script class=marko-vite-preload>document.documentElement.style.visibility='hidden'</script>";
}
}`
}
Expand Down

0 comments on commit 4136b09

Please sign in to comment.