Real-time preview for props changes of JS components

Created on 23 March 2025, 3 months ago

Overview

As a content editor building a page using (JavaScript) Code Components, when I update prop values in the right sidebar, I want to see the preview update immediately, without waiting to get a response from the server.

It would be great to have this when using SDCs as well, but that's harder, so isn't part of this issue's scope. That would need its own child issue of 📌 Implement endpoint for realtime preview Active .

Proposed resolution

  • We need a way to get a prop value from the widgets (form input elements) in the right sidebar. 📌 Move clientside assumptions about prop form data shape into a series of prop specific transforms Active made that possible for at least some widgets. This issue's scope is only for the cases where we have that. For widgets that require a round trip to the server in order to map to field value and prop value, we don't get the real-time preview update.
  • Assuming we can get the updated prop value client-side, we can update the preview by simply targeting the <astro-island> element for this component instance, and updating its props attribute. The Astro island will then automatically re-render itself client-side based on the new props.
  • We should still send the request to the server, in order to auto-save our changes. However, we could potentially experiment with different debounce thresholds. For example, update the preview with a <1 second (maybe <0.1s?) debounce and auto-save to the server with a >1 second (maybe >5s?) debounce.

User interface changes

Feature request
Status

Active

Version

0.0

Component

Page builder

Created by

🇺🇸United States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @effulgentsia
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
    • Assuming we can get the updated prop value client-side, we can update the preview by simply targeting the <astro-island> element for this component instance, and updating its props attribute. The Astro island will then automatically re-render itself client-side based on the new props.

    I forget the details of how our undo/redo functionality is implemented exactly (and I see we're missing docs for it other than a one-liner 🫣), but … AFAICT this would then have to add Component Source-specific logic to perform undo+redo. It'd need to check every affected component instance when undoing/redoing, check if it's provided by the js ComponentSource plugin, and then perform this alternative.
    And if and only if there's zero other component instances affected, then that's all that's needed. But if there's >=1 component instance from another component source that needs undoing/redoing, we still need to talk to the server, because the server can only update the entire preview, not a subset.

    (And I bet there's more complications.)

  • 🇺🇸United States effulgentsia

    Is there a reason we don't include the preview HTML in the undo stack? Thereby allowing all undo operations (regardless of what kinds of components are on the page) to optimistically render before the server response?

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Fair question. I suspect because "memory usage will go through the roof".

  • Assigned to jessebaker
  • 🇺🇸United States effulgentsia

    Tagging this as a beta blocker, because we want early adopters of the beta able to run XB in production, including under potentially heavy server load.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I think @effulgentsia implies with "heavy server load" that he wants Content Creators using XB to have a good experience, which implies a low-latency experience, even when latency is high (either high client → server network latency or simply the server response latency being high, aka high server load).

    If so, can we start with implementing this while accepting that not every prop's resolved value (see: EvaluatedComponentModel

    My concrete proposal:

    1. for many prop shapes, we already have client-side transforms for the used field widget
    2. we have JSON Schema information for each such prop, which allows client-side validation of the resolved value against the JSON Schema
    3. restrict scope of this issue to only those prop shapes where #1 (a client-side transforms) exists, and which meets #2 (transforms to a valid resolved value per the JSON Schema for that prop)
    4. leave EVERYTHING ELSE to follow-up issues: A) client-side transform exists but does not pass client-side JSON Schema validation, B) client-side transform does not yet exist but is possible, C) client-side transform to resolved value is impossible (for example: media library widget), but we could do some client-side caching — A+B+C can then be follow-ups that improve the state this issue would put us in.

    That way, we can start implementation any time (even today), and learn what the most valuable missing pieces would be.

  • 🇫🇮Finland lauriii Finland

    restrict scope of this issue to only those prop shapes where #1 (a client-side transforms) exists, and which meets #2 (transforms to a valid resolved value per the JSON Schema for that prop)

    Where can I find a list of prop types that meet this criteria?

Production build 0.71.5 2024