Skip to content

Commit 8de07ff

Browse files
committed
fix(player): drop the empty transition label from the Loading assets card
The Loading assets card reuses the shader-transition panel, and resetting it hid the transition-frame row but not the transition row, so a bare "transition" label stayed under the progress bar. Each progress row now shows only while it has a value, which also covers a shader load that reports no count yet.
1 parent 99221c5 commit 8de07ff

3 files changed

Lines changed: 62 additions & 6 deletions

File tree

‎packages/player/src/shader-loader-element.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ShaderLoaderElements {
1515
title: HTMLSpanElement;
1616
detail: HTMLDivElement;
1717
transitionValue: HTMLSpanElement;
18+
transitionRow: HTMLDivElement;
1819
frameLabel: HTMLSpanElement;
1920
frameValue: HTMLSpanElement;
2021
frameRow: HTMLDivElement;
@@ -119,6 +120,7 @@ export function createShaderLoader(): ShaderLoaderElements {
119120
title: titleText,
120121
detail,
121122
transitionValue: transitionStatus.value,
123+
transitionRow: transitionStatus.row,
122124
frameLabel: frameStatus.label,
123125
frameValue: frameStatus.value,
124126
frameRow: frameStatus.row,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @vitest-environment happy-dom
2+
import { describe, expect, it } from "vitest";
3+
import { createShaderLoader } from "./shader-loader-element.js";
4+
import { ShaderLoaderState } from "./shader-loader-state.js";
5+
6+
function loader() {
7+
const elements = createShaderLoader();
8+
const visibleLabels = () =>
9+
[...elements.root.querySelectorAll<HTMLElement>(".hfp-shader-loader-row")]
10+
.filter((row) => row.style.visibility !== "hidden")
11+
.map((row) => row.querySelector(".hfp-shader-loader-label")?.textContent);
12+
return { state: new ShaderLoaderState(elements), visibleLabels };
13+
}
14+
15+
describe("shader loader progress rows", () => {
16+
it("shows no progress rows on the Loading assets card", () => {
17+
const { state, visibleLabels } = loader();
18+
state.showAssetsLoading();
19+
expect(visibleLabels()).toEqual([]);
20+
});
21+
22+
it("hides the transition rows a shader load left behind when assets start loading", () => {
23+
const { state, visibleLabels } = loader();
24+
state.update(
25+
{
26+
loading: true,
27+
ready: false,
28+
currentTransition: 1,
29+
transitionTotal: 3,
30+
transitionFrame: 2,
31+
transitionFrames: 30,
32+
},
33+
"player",
34+
);
35+
expect(visibleLabels()).toEqual(["transition", "rendering transition frames"]);
36+
37+
state.showAssetsLoading();
38+
expect(visibleLabels()).toEqual([]);
39+
});
40+
41+
it("shows the transition row only once it has a count", () => {
42+
const { state, visibleLabels } = loader();
43+
state.update({ loading: true, ready: false }, "player");
44+
expect(visibleLabels()).toEqual([]);
45+
46+
state.update({ loading: true, ready: false, progress: 2, total: 5 }, "player");
47+
expect(visibleLabels()).toEqual(["transition"]);
48+
});
49+
});

‎packages/player/src/shader-loader-state.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import type { ShaderLoaderElements } from "./shader-loader-element.js";
1414

1515
const HIDE_TRANSITION_MS = 420;
1616

17+
/** A progress row shows only while it has a value, so no bare label is left on the card. */
18+
function setRowValue(row: HTMLElement, value: HTMLElement, text: string): void {
19+
value.textContent = text;
20+
row.style.visibility = text ? "visible" : "hidden";
21+
}
22+
1723
export class ShaderLoaderState {
1824
private readonly _el: ShaderLoaderElements;
1925
private _hideTimeout: ReturnType<typeof setTimeout> | null = null;
@@ -65,9 +71,8 @@ export class ShaderLoaderState {
6571
this._el.root.classList.remove("hfp-visible", "hfp-hiding");
6672
this._flushHidden();
6773
this._el.fill.style.transform = "scaleX(0)";
68-
this._el.transitionValue.textContent = "";
69-
this._el.frameValue.textContent = "";
70-
this._el.frameRow.style.visibility = "hidden";
74+
setRowValue(this._el.transitionRow, this._el.transitionValue, "");
75+
setRowValue(this._el.frameRow, this._el.frameValue, "");
7176
}
7277

7378
// fallow-ignore-next-line unused-class-member, complexity
@@ -107,7 +112,7 @@ export class ShaderLoaderState {
107112
this._el.fill.style.transform = `scaleX(${ratio})`;
108113

109114
// fallow-ignore-next-line code-duplication
110-
this._el.transitionValue.textContent =
115+
const transitionValue =
111116
status.currentTransition !== undefined && status.transitionTotal !== undefined
112117
? `${status.currentTransition}/${status.transitionTotal}`
113118
: total > 0
@@ -126,8 +131,8 @@ export class ShaderLoaderState {
126131
? "finalizing transition frames"
127132
: "rendering transition frames";
128133

129-
this._el.frameValue.textContent = frameValue;
130-
this._el.frameRow.style.visibility = frameValue ? "visible" : "hidden";
134+
setRowValue(this._el.transitionRow, this._el.transitionValue, transitionValue);
135+
setRowValue(this._el.frameRow, this._el.frameValue, frameValue);
131136
this._el.root.setAttribute("aria-valuenow", String(Math.round(ratio * 100)));
132137
this.show();
133138
}

0 commit comments

Comments
 (0)