Overview

Currently, when a prop is invalid and that value (or lack of one) is sent to the backend, that component in the preview is replaced with a generic "Component failed to render" message. This seems to be seen as an error that should be avoided at all costs, but it's actually an effective way of conveying that the current value is not an acceptable one.
If it provides a more detailed message regarding the validation problem + styled in a manner that feels more deliberate, this will likely be more useful.

Proposed resolution

User interface changes

CommentFileSizeAuthor
#12 selected.png134.8 KBbnjmnm
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bnjmnm created an issue. See original summary.

wim leers’s picture

Title: Invalid prop errors should be detailed in Component preview » Invalid prop errors should be detailed in Component preview; otherwise the preview LIES 😱
Assigned: bnjmnm » Unassigned
Priority: Major » Critical
Issue tags: +stable blocker, +Usability
Related issues: +#3528396: Video prop shape: e2e test coverage for video from media library the component instance form + fix revealed bug in evaluating `StaticPropSource`s

wim leers’s picture

Title: Invalid prop errors should be detailed in Component preview; otherwise the preview LIES 😱 » [needs design] Invalid prop errors should be detailed in Component preview; otherwise the preview LIES 😱
Assigned: Unassigned » lauriii
Issue tags: +Needs design, +Needs product manager review

This is something @effulgentsia, @bnjmnm, I and possibly others discussed before this issue was created.

@lauriii wasn't around then. It came up again a few days ago. Thanks to @neha_bawankar the very confusing impact for content authors is now much clearer.

Time for Lauri to chime in and to work with designers to articulate a way forward here.

larowlan’s picture

Per #3529788-32: Required `type: string` (without other constraints, so "prose strings") props should fall back to empty string (even though invalid) while Content Author is typing, to allow matching live preview in most cases we also need to take into account when zend.assertions are set to 1 as that will also cause a render fail from \Drupal\Core\Template\ComponentsTwigExtension::validateProps which is dynamically injected into each component's twig template via \Drupal\Core\Template\ComponentNodeVisitor

Even if XB doesn't validate component input when creating the preview, that code will when assert is enabled.

We could either:

  • Detect asserts are on and swap out the validator to do nothing on preview routes, OR
  • Adapt the 'component failed to render' message to include assert is enabled messaging

I would vote for the first option as having to disable assert during development could be silently muting other errors

isholgueras’s picture

If the issue is the

          $component = Component::load($component_instance['component']);
          assert($component instanceof Component);

Could we change only this assert with a regular if if we're in preview? Something like this draft code:

          $component = Component::load($component_instance['component']);
          // Avoid asserts in preview with zend.assertions=1 to improve message to users.
          if (!$isPreview) {
            assert($component instanceof Component);
          }
          elseif (!$component instanceof Component) {
            // Or anything else.
            throw new ComponentNotFoundException($component_instance['component'] . ' doesn\'t exist.');
          }

I'm probably missing something but that's the only assert we need to sort, right?

I was completely wrong. The assert is the one that Lee is describing, from Core, in

  public function validateProps(array &$context, string $component_id): void {
    assert($this->doValidateProps($context, $component_id));
  }
wim leers’s picture

larowlan’s picture

It will depend on the twig file.

Something like a missing title here

<h1>{{ title }}</h1>

Would be white, but in other cases, there might be a fatal

{{ some_invalid_thing|t }}

We won't get to live site, because validation will prevent publishing

larowlan’s picture

Assigned: larowlan » Unassigned
wim leers’s picture

Oh, right. Great, then #6 is a solid plan! 👍 Thanks :)

bnjmnm’s picture

StatusFileSize
new134.8 KB

The 3530795-validation-render branch has an approach that looks like this:
Rendering error

The screenshot was taken before we added support to gracefully handle empty required fields - mentally replace that message with any of the many possible render-crashing errors that can't be handled so smoothly. The design is just rough, the main things to note is the unrenderable component has a clear message in its place, and the guilty prop input is correctly highlighted as invalid.

wim leers’s picture

Version: 0.x-dev » 1.x-dev
Assigned: Unassigned » lauriii
Status: Active » Postponed (maintainer needs more info)

Thanks, Ben!

wim leers’s picture

Assigned: lauriii » callumharrod

Discussed in meeting with @callumharrod, @lauriii and @bnjmnm. There's some more clarity now, but still plenty left to be clarified. @callumharrod is working on expanded designs to demonstrate how this is expected to work:

  1. when an invalid prop value is auto-saved for a component instance being edited currently (optimistic rendering whenever possible — for now only one case — see #3529788: Required `type: string` (without other constraints, so "prose strings") props should fall back to empty string (even though invalid) while Content Author is typing, to allow matching live preview in most cases+ #3537945: Narrow the conditions under which we allow a prop to be an empty string — potentially more in the future)
  2. when an invalid prop value is auto-saved for a component instance NOT being edited currently, only being previewed (never optimistically rendered — visually similar to @bnjmnm's #12, but with different styling, and most importantly: with dimensions retrieved from the component's default representation based on example values)
  3. showcasing the workflow when opening an auto-saved Page with many component instances of which e.g. 3 have invalid values auto-saved for >=1 prop, including whether the preview canvas should auto-scroll the first invalid component instance into view
  4. (not discussed but just realized: the design should visualize what to do when multiple props have invalid values auto-saved)
effulgentsia’s picture

Is the "preview LIES" part of this issue title still accurate? The way I read the comment linked in #3 is that there are situations where you can publish something while it still have invalid values. If those cases still exist, shouldn't those be separate issues? Meanwhile, if you can't publish with invalid values, then what do we mean by the preview lying?

effulgentsia’s picture

Project: Experience Builder » Drupal Canvas
effulgentsia’s picture

Issue tags: -stable blocker

Discussed this with @lauriii and seems like the stable blocking parts of this have already landed so what remains doesn't need to block a stable release.