Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

393
Vistas
StencilJS: How to prevent "flickering" when loading component in a page

A group of volunteers has created a single/multi-select component using StencilJS: https://github.com/NothingAG/adg-components

Now we want to hand it over to the client so they can use it in their project. But we notice that loading the component seems to take some time after the page itself loaded, so some flickering appears (when the loaded component claims its horizontal space):

enter image description here

Is this normal behaviour of such a component? Or how can we allocate the needed space when the browser is rendering? We could try to simply use min-height or something with a fixed value, but this feels like a hack and may change over time.

Thanks a lot for help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is normal. A Stencil web component will go through its load lifecycle asynchronously after being loaded into DOM, and therefore it may not complete until after the DOM has completed loading and the page is rendered. If the component has to make a call to fetch data for example before it fully renders, that might take long enough for this "flicker" to be noticeable.

Strategies for dealing with this type of situation will depend on the component, but in your case it looks like one approach would be to render the labels and controls without selection items and maybe disabled so that the initial render can occur early, and trigger a component update via a State variable when fetched data becomes available which simply populates the selection controls, and possibly enables them.

So - and I'm making guesses about how your component works - rather than conditionally render the controls, conditionally populate the controls.

Crude example of rendering a select element empty until data is set on the component via a property (code not validated):

private _selectionItems = [];
@Prop() selectionItems: string = ''; // csv list of select options
@Watch('selectionItems') 
setSelectionItems(selectionItems: string) {
    selectionItems = selectionsItems || ''; // null check
    this._selectionItems = selectionItems.split(',');
}

render() {
    return (
        <label for="my-select">Choose an item:</label>

        <select id="my-select">
            {this._selectionItems.map(
                item: string => <option value={item}>{item}</option>
            )}
        </select>
    );
}

Contrast with not rendering at all until data is set (showing render function only):

render() {
    if (this._selectionItems.length > 0) {
        return (
            <label for="my-select">Choose an item:</label>

            <select id="my-select">
                {this._selectionItems.map(
                    item: string => <option value={item}>{item}</option>
                )}
            </select>
        );
    }
    else {
        return null;
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda