Skip to content

Commit

Permalink
#167 new build waiting on load to avoid blocking the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed Nov 1, 2024
1 parent 760d780 commit d01f8c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cast/static/cast/vite/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"src/audio/podlove-player.ts": {
"file": "podlovePlayer-vU4Jjjws.js",
"file": "podlovePlayer-Cn4SwLmX.js",
"name": "podlovePlayer",
"src": "src/audio/podlove-player.ts",
"isEntry": true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class d extends HTMLElement{constructor(){super(),this.observer=null,this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.renderPlaceholder(),this.observeElement()}disconnectedCallback(){this.observer&&this.observer.disconnect()}renderPlaceholder(){const e=document.createElement("div");e.classList.add("podlove-player-container");const t=document.createElement("style");t.textContent=`
class d extends HTMLElement{constructor(){super(),this.observer=null,this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.renderPlaceholder(),document.readyState==="complete"?this.observeElement():window.addEventListener("load",()=>{this.observeElement()},{once:!0})}disconnectedCallback(){this.observer&&this.observer.disconnect()}renderPlaceholder(){const e=document.createElement("div");e.classList.add("podlove-player-container");const t=document.createElement("style");t.textContent=`
.podlove-player-container {
width: 100%;
max-width: 936px;
Expand Down
11 changes: 10 additions & 1 deletion javascript/src/audio/podlove-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ class PodlovePlayerElement extends HTMLElement {

connectedCallback() {
this.renderPlaceholder();
this.observeElement();

if (document.readyState === 'complete') {
// The page is already fully loaded
this.observeElement();
} else {
// Wait for the 'load' event before initializing
window.addEventListener('load', () => {
this.observeElement();
}, { once: true });
}
}

disconnectedCallback() {
Expand Down

0 comments on commit d01f8c2

Please sign in to comment.