fix(html): avoid menu item value render loop (#1791)

This commit is contained in:
Sam Potts
2026-07-02 15:11:19 +10:00
committed by GitHub
parent 6f6657a198
commit 47e74a139e
4 changed files with 49 additions and 4 deletions
@@ -17,6 +17,9 @@ export class MenuItemValueElement extends MediaElement {
protected override update(_changed: PropertyValues): void {
super.update(_changed);
this.textContent = this.#ctx.value?.label ?? '';
const label = this.#ctx.value?.label ?? '';
if (this.textContent !== label) {
this.textContent = label;
}
}
}
@@ -172,6 +172,26 @@ describe('MenuItemValueElement', () => {
});
});
it('does not rewrite an unchanged label', async () => {
const { value } = setup(createPlaybackRateStore({ playbackRate: 1.5 }), 'playback-rate');
await value.updateComplete;
await waitForAssertion(() => {
expect(value.textContent).toBe('1.5×');
});
const mutations: MutationRecord[] = [];
const observer = new MutationObserver((records) => mutations.push(...records));
observer.observe(value, { childList: true, characterData: true, subtree: true });
value.requestUpdate();
await value.updateComplete;
await nextFrame();
observer.disconnect();
expect(mutations).toHaveLength(0);
});
it('renders Off when captions are disabled', async () => {
const { value } = setup(
createTextTrackStore({