Skip to content

Commit 073f075

Browse files
index3: wait for the player stylesheet before mounting a demo
asciinema-player reads its palette from the --term-color-* custom properties once, when the terminal view mounts, and falls back to an all-black theme (foreground, background and all 16 palette entries) when they do not resolve. The lazy loader only waited for the script, so on a cold load the player could mount before the stylesheet had been applied and render the recording black on black. Wait for both tags. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9916c45 commit 073f075

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

index3.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,20 +1634,23 @@ <h2>Trusted by sysadmins, hoarders and the merely paranoid.</h2>
16341634
{ borg: '2.0', title: 'guided tour', file: '_assets/borg2-demo.cast', dur: '4 min 2 s', speed: 1.0 },
16351635
];
16361636

1637-
// the player JS/CSS are heavy, so they only load once the section is near
1638-
let assets = null;
1639-
const loadAssets = () => assets ??= new Promise((resolve, reject) => {
1640-
const css = document.createElement('link');
1641-
css.rel = 'stylesheet';
1642-
css.href = '_assets/asciinema-player-v3.15.1.css';
1643-
document.head.appendChild(css);
1644-
const js = document.createElement('script');
1645-
js.src = '_assets/asciinema-player-v3.15.1.min.js';
1646-
js.onload = resolve;
1647-
js.onerror = () => reject(new Error('player load failed'));
1648-
document.head.appendChild(js);
1637+
// the player JS/CSS are heavy, so they only load once the section is near.
1638+
// both have to be waited for: the player reads its palette from the
1639+
// --term-color-* custom properties once, at mount, and falls back to an
1640+
// all-black theme when the stylesheet has not been applied yet.
1641+
const loadTag = (tag, attrs) => new Promise((resolve, reject) => {
1642+
const el = Object.assign(document.createElement(tag), attrs);
1643+
el.onload = resolve;
1644+
el.onerror = () => reject(new Error(`${attrs.href || attrs.src} failed to load`));
1645+
document.head.appendChild(el);
16491646
});
16501647

1648+
let assets = null;
1649+
const loadAssets = () => assets ??= Promise.all([
1650+
loadTag('link', { rel: 'stylesheet', href: '_assets/asciinema-player-v3.15.1.css' }),
1651+
loadTag('script', { src: '_assets/asciinema-player-v3.15.1.min.js' }),
1652+
]);
1653+
16511654
let current = -1;
16521655
let player = null;
16531656
const show = (idx) => {

0 commit comments

Comments
 (0)