Overview

Quoting @penyaskito from #3470422-68: Handle components provided by ComponentSources IMPLICITLY disappearing: gracefulness when developing SDCs: SDCs may appear/disappear from one request to the next:

why the client sends form_canvas_props: undefined, instead of an actual JSON blob. (When the fallback source is in use, the client should send the model it has for this component instance, not the values for the component instance form.)

See https://git.drupalcode.org/project/canvas/-/merge_requests/142#note_598244, which was forced to introduce a server-side work-around which is causing further pain in subsequent MRs: https://git.drupalcode.org/project/canvas/-/merge_requests/220/diffs#not....

Worse, since then, we've regressed: block component instances (only for block component instances could form_cavas_props: undefined get sent!) no longer offer the fallback behavior

  1. I placed/instantiated core's "branding" block.
  2. Then deleted core/modules/system/src/Plugin/Block/SystemBrandingBlock.php
  3. drush cr
  4. When editing again:

It also means \Drupal\Tests\canvas\Kernel\ComponentInstanceFormTest::testBlockComponentThatHasGoneAway() is testing a client reality that has vanished — (what should have been an E2E test)

Proposed resolution

  1. 🚢 MR#1: Improve comment clarity for the complex fallback logic that #3519168: Handle components provided by ComponentSources EXPLICITLY disappearing — enables deleting JS components that are in use introduced in \Drupal\canvas\Form\ComponentInstanceForm::buildForm(). (The lack of sufficient comments has made this much harder to work on.)
  2. MR#2:
    1. Fix the JS error in the GIF in the STR above.
    2. Remove the server-side work-around
    3. Determine the root cause of the bug on the client side and fix it.

User interface changes

Works again like #3519168: Handle components provided by ComponentSources EXPLICITLY disappearing — enables deleting JS components that are in use intended, but now without special babysitting for component sources other than SDC/code components. 👍

Issue fork canvas-3558721

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

wim leers created an issue. See original summary.

wim leers’s picture

Also credited @penyaskito for his original work in identifying the bug and figuring out a viable work-around: https://git.drupalcode.org/project/canvas/-/merge_requests/142/diffs#not....

P.S.: I suspect this goes all the way back to how support for block forms was introduced in #3491978: Implement saving block settings forms.

wim leers’s picture

Issue tags: -JavaScript +JavaScript

Bump.

wim leers’s picture

Status: Active » Needs review
Issue tags: +Needs manual testing

Looks like we actually don't need that, and it passes tests? 🤔

wim leers’s picture

Related issues:

#3470422: Handle components provided by ComponentSources IMPLICITLY disappearing: gracefulness when developing SDCs: SDCs may appear/disappear from one request to the next significantly changed the lines this was updating; hope I got the update right.

EDIT: apparently I was the one who removed the block-specific bits over at https://git.drupalcode.org/project/canvas/-/merge_requests/220/diffs?com... 🤯 No recollection of this.

wim leers’s picture

AFAICT #3577219: Add Multi-Value Image/Video Prop Support (UI)'s https://git.drupalcode.org/project/canvas/-/merge_requests/755 addressed this:

-  resolved[propName] = isRequired
-    ? propSourceData.default_values.resolved
-    : undefined;
+  resolved[propName] = isRequired ? propSourceData.default_values.resolved : [];

Merged in upstream. Re-testing.

wim leers’s picture

Title: UI must never send `form_canvas_props: "undefined"` to the component instance form » Regression: can no longer access previously stored values for block component instances
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs manual testing +data loss, +Needs issue summary update
StatusFileSize
new187.59 KB

Improved the clarity of the else branch (meaning "component powering this component instance is broken").

This actually brought us to failing tests that fail for the very reason this issue was opened: the client is sending nothing, whereas it should send the client-side data model it does have. IOW: \Drupal\Tests\canvas\Kernel\ComponentInstanceFormTest::testBlockComponentThatHasGoneAway() is replicating the client-side bug in a PHPUnit test;

$response = $this->getCrawlerForFormRequest('/canvas/api/v0/form/component-instance/canvas_page/' . $page->id(), $component, json_decode('undefined'));

That json_decode('undefined') bit at the end is the problem.

Reproducibility in current UI

So I set out to reproduce this.

  1. I placed/instantiated core's "branding" block.
  2. Then deleted core/modules/system/src/Plugin/Block/SystemBrandingBlock.php
  3. drush cr
  4. When editing again:

That means the answer to Determine the root cause of the bug on the client side and fix it. in the issue summary is: "cannot reproduce at all", so the server-side work-around by definition is not necessary right now 😅

Meaning you can no longer even get to the component instance form to recover values (which was the very purpose of #3519168: Handle components provided by ComponentSources EXPLICITLY disappearing — enables deleting JS components that are in use).

It also means \Drupal\Tests\canvas\Kernel\ComponentInstanceFormTest::testBlockComponentThatHasGoneAway() is testing a client reality that is no longer a reality — an inherent risk of replicating client behavior in a PHPUnit test.

wim leers’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS.

Proposing 2 MRs:

  1. The current one, which only brings more clarity to the server-side code by adding comments.
  2. A new one, to fix the client-side regression and which should allow us to simplify the server-side code.

wim leers’s picture

Assigned: Unassigned » penyaskito
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +triaged

Bumping to critical because this will lead to:

NR for the first MR. That can land and improve the clarity of what needs to happen.

wim leers’s picture

  • wim leers committed df1f05b1 on 1.x
    chore(Component sources): #3558721 Clarify the intended and actual...
wim leers’s picture

Assigned: penyaskito » Unassigned
Issue summary: View changes
Status: Needs review » Active

Landed MR #1. MR #2 updated with pointers.

wim leers’s picture

Issue summary: View changes