Loading States

Show spinners, disable buttons, and provide feedback during server requests. Loading states appear automatically during method calls and property updates.

Basic loading

Use lace:loading to show an element during any loading state. Combine with lace:loading.hidden to hide elements while loading.

PREVIEW

Count: 0

class LoadingBasic(Component):

    count: int = 0

    def increment(self):
        time.sleep(1)  # Simulate work
        self.count += 1

    def inline_template(self):
        return """
        <div class="...">
            <p class="...">Count: {{ count }}</p>
            <button lace:click="increment" class="...">
                <span lace:loading.hidden>Click Me</span>
                <span lace:loading.flex class="...">Processing...</span>
            </button>
        </div>
        """

First load vs refresh

lace:loading.init fires only for the initial deferred load (from lace:init or a lazy component); lace:loading.proceeding fires for every load after that. A common pattern is a skeleton on first load but a lighter treatment on refresh, since the data is already on screen. Here the skeleton shows once, and later refreshes just dim the existing rows via lace:loading.proceeding.class. Wait for the first load, then hit Refresh:

PREVIEW

Activity

class LoadingInit(Component):
    rows: list = []

    def load(self):
        self.rows = fetch_activity()

    def inline_template(self):
        return """
        <div lace:init="load">
            <button lace:click="load">Refresh</button>

            {# first load only: a skeleton #}
            <div lace:loading.init class="animate-pulse">
                <div class="skeleton-row"></div>
                <div class="skeleton-row"></div>
            </div>

            {# the data: hidden on first load, dimmed on later refreshes #}
            <div lace:loading.init.hidden lace:loading.proceeding.class="opacity-40">
                {% for row in rows %}<div>{{ row }}</div>{% endfor %}
            </div>
        </div>
        """

Targeted loading

Show different loading states for different actions using lace:target. Each loader appears only when its specific method is called.

PREVIEW

Status: Ready

class LoadingTargeted(Component):
    status: str = "Ready"

    def save(self):
        time.sleep(1)
        self.status = "Saved!"

    def delete(self):
        time.sleep(1)
        self.status = "Deleted!"

    def inline_template(self):
        return """
        <div class="...">
            <p>Status: {{ status }}</p>
            <button lace:click="save" class="...">
                <span lace:loading.hidden lace:target="save">Save</span>
                <span lace:loading.flex lace:target="save">Saving...</span>
            </button>
            <button lace:click="delete" class="...">
                <span lace:loading.hidden lace:target="delete">Delete</span>
                <span lace:loading.flex lace:target="delete">Deleting...</span>
            </button>
        </div>
        """

CSS class modifier

Add CSS classes during loading with lace:loading.class. Useful for disabling buttons or dimming content without hiding it.

PREVIEW

Button becomes disabled and semi-transparent during loading

class LoadingClass(Component):
    result: str = ""

    def submit(self):
        time.sleep(1.5)
        self.result = "Form submitted successfully!"

    def inline_template(self):
        return """
        <div class="...">
            <button
                lace:click="submit"
                lace:loading.class="opacity-50 cursor-not-allowed"
                class="..."
            >
                Submit Form
            </button>
            {% if result %}<p class="...">{{ result }}</p>{% endif %}
        </div>
        """

Live search loading

Loading states work with live model updates. Show a spinner while debounced searches execute.

PREVIEW
class LoadingSearch(Component):

    query: str = ""
    results: list = []

    def updated_query(self, value):
        if value:
            time.sleep(0.5)
            self.results = [
                f"Result for '{value}' #1",
                f"Result for '{value}' #2",
                f"Result for '{value}' #3",
            ]
        else:
            self.results = []

    def inline_template(self):
        return """
        <div class="...">
            <input
                type="text"
                lace:model.live.debounce.500ms="query"
                placeholder="Type to search..."
            />
            <div lace:loading></div>
            {% if results %}
            <ul>
                {% for result in results %}
                <li>{{ result }}</li>
                {% endfor %}
            </ul>
            {% endif %}
        </div>
        """

Reference

See lace:loading for every modifier, and lace:target for scoping a loader to specific methods.

View this page as markdown - handy as context for your AI tools. Full index at /llms.txt.

Theme
Accent
Ink