Skip to content

Commit

Permalink
fix: theme render flicker (breakpoints)
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Aug 16, 2024
1 parent f007331 commit a378ce4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/js/media-theme-element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MediaStateChangeEvents } from './constants.js';
import MediaController from './media-controller.js';
import { getOrInsertCSSRule } from './utils/element-utils.js';
import { globalThis, document } from './utils/server-safe-globals.js';
import { TemplateInstance } from './utils/template-parts.js';
import { processor } from './utils/template-processor.js';
Expand All @@ -13,13 +14,20 @@ const observedMediaAttributes = {
mediastreamtype: 'streamtype',
};

// For hiding the media-theme element until the breakpoints are available
// display: none can't be used because it would prevent the element or its
// children (media-controller) from getting dimensions.

const prependTemplate = document.createElement('template');

prependTemplate.innerHTML = /*html*/ `
<style>
:host {
display: inline-block;
line-height: 0;
/* Hide theme element until the breakpoints are available to avoid flicker. */
visibility: hidden;
}
media-controller {
Expand Down Expand Up @@ -242,6 +250,9 @@ export class MediaThemeElement extends globalThis.HTMLElement {

render(): void {
this.renderer?.update(this.props);

const { style } = getOrInsertCSSRule(this.renderRoot, ':host');
style.setProperty('visibility', 'visible');
}
}

Expand Down

0 comments on commit a378ce4

Please sign in to comment.