Overview

Code components, once they're added to components, i.e. become exposed, lock props and slots. This was implemented in #3500081: Editing components sourced as code components.

On a related issue, #3509089: Code component status is not reflected in the code editor, @lauriii raised the following:

the updated status is not reflected in the code editor when the component's code is edited, which is supposed to lock props and slots

This seems like a pretty drastic consequence. I think we need follow-up issue to find a better way for managing this because it's fairly normal that especially during the initial development of a site that props might change.

Comment by @balintbrews:

[...] it was an easy consensus within the team that we need to ensure that once a component is exposed, which means it can be used for content, we need to ensure data integrity. Props can be updated by moving the component back to internal, where the prerequisite is that it's not used on the page. Maybe we can forego locking props and slots when that prerequisite is met. Happy to discuss in a follow-up.

Comment by @Wim Leers:

Agreed with [comment by @balintbrews]. That requires us knowing whether there's any instances of the code component, as described by @tedbow at #3500043-3: Publishing code components

Proposed resolution

Back-end changes needed

No back-end changes needed

Combined front-end changes

User interface changes

TBD

Issue fork canvas-3509115

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

balintbrews created an issue. See original summary.

balintbrews’s picture

wim leers credited tedbow.

wim leers’s picture

wim leers’s picture

Related: #3500074: Usage info for code components with unpublished changes. Because … it'd be 100% safe to change props and slots whenever as long as there are no instances yet. And thanks to #3457504: XB field type: calculate all dependencies, store them, surface in new Component "Audit" operation, that's now actually possible.

IOW: the conversation here needs to be forked along two paths:

  1. 0 instances exist: anything is allowed
  2. >=1 instances exist: care is needed
wim leers’s picture

Note: a new required prop would actually be trivial to support. Because XB requires required props to have an example value!

Especially since #3518336: When a field instance used by a `ContenTemplate` is deleted, or a field-type providing module is uninstalled, replace affected `inputs` with default `StaticPropSource` just added ::getDefaultExplicitInput(), this would be easy to support.

Conceptually speaking, the needed changes would be:

  1. ComponentTreeHydrated would have to change from
    $source->renderComponent($stored_explicit_input)
    

    to

    $source->renderComponent($stored_explicit_input + $source->getDefaultExplicitInput())
    
  2. EITHER ValidComponentTreeConstraintValidator would need to be updated to relax from
    $component_source->validateComponentInput(
              inputValues: $stored_explicit_input,
              component_instance_uuid: $component_instance_uuid,
              entity: $host_entity,
            ),
    

    to also do + $source->getDefaultExplicitInput()

    OR

    \Drupal\experience_builder\Controller\ClientServerConversionTrait::convertClientToServer() should do + $source->getDefaultExplicitInput(), which would ensure that any edit to any component tree would automatically add new required props' default values.

wim leers’s picture

Component: Page builder » Theme builder
Priority: Normal » Major
Issue tags: +data integrity, +Usability

Important for usability of Code Component creators.

Critical for XB's data integrity when we add support for changing props/slots.

wim leers’s picture

Title: Plan to allow editing props and slots for exposed code components » [META] Plan to allow editing props and slots for exposed code components
Assigned: Unassigned » lauriii
Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs product manager review
Related issues: +#3530058: Only allow deleting Code Components if there's 0 usages (so: 0 instances in auto-saves, default content entity revisions, config dependencies — ignoring past & forward revisions)

@lauriii, please see the proposed resolution.

Project: Experience Builder » Drupal Canvas
Version: 0.x-dev » 1.x-dev

Experience Builder has been renamed to Drupal Canvas in preparation for its beta release. You can now track issues on the new project page.

lauriii’s picture

Assigned: lauriii » Unassigned
Status: Needs review » Needs work
Issue tags: -Needs product manager review

The scope of this issue is both props and slots but it looks like the issue summary is only talking about props. Adding the 'Needs issue summary update' tag to expand the proposed solution to include slots.

never allowing prop shapes to be changed, unless there's zero instances

I think we should allow this to be done. Prop data will be either converted to the new prop type (when possible) or deleted (when conversion is not possible) when component with the changed prop type is loaded.

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Added child issues and updated the issue summary to reference them

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Issue summary: View changes

penyaskito made their first commit to this issue’s fork.

larowlan’s picture

Issue summary: View changes
wim leers’s picture

Assigned: Unassigned » lauriii
Status: Needs work » Postponed (maintainer needs more info)

Prop data will be either converted to the new prop type (when possible)

You can state that if you want, but that's not a trivial undertaking. Different field types might support the same prop shape, but might store data completely differently.

A number of field types for example use computed properties, and it's only the computed properties that can populate a certain prop shape … the stored data may not even look like it.

And that's just when the prop shape remains the same! You're talking about changing the prop shape, which is an even more difficult transition.

So -1 for including that in the scope here. That's #3463996: [META] [PP-1] When the field type, storage/instance settings, widget, expression or requiredness for an SDC/code component prop changes, the Content Creator must be able to upgrade territory, and would be a significant scope expansion even there.

or deleted (when conversion is not possible) when component with the changed prop type is loaded.

Huh?! 🤯 How is that not data loss? Can you please elaborate?

EDIT: and the current issue summary still also indicates that we won't support this:

So perhaps I'm just misreading what @lauriii wrote here? 😅

lauriii’s picture

Assigned: lauriii » Unassigned
Status: Postponed (maintainer needs more info) » Active

I think it's fine to punt that feature to a follow-up issue which we may or may not prioritize depending on feedback. I don't think it's the most critical aspect of this issue. The reason I think we should consider doing that is to avoid data loss like you mention. However, we still should allow changing the prop type by first deleting the prop and then adding a new prop with the same name. It includes a delete action which makes it clear that data loss is involved.

larowlan’s picture

larowlan’s picture

.

effulgentsia’s picture

Issue summary: View changes

.

effulgentsia’s picture

Issue summary: View changes

.

effulgentsia’s picture

Issue summary: View changes

Organizing list of issues in summary into sections.

effulgentsia’s picture

Issue summary: View changes

.

larowlan’s picture

Issue summary: View changes

  • larowlan committed d8a90638 on 1.x
    feat: #3509115 [META] Plan to allow editing props and slots for exposed...
larowlan’s picture

.

larowlan’s picture

.

penyaskito’s picture

wim leers’s picture

That MR that landed, wow … \Drupal\Tests\canvas\Kernel\Plugin\Canvas\ComponentSource\JsComponentEvolutionTest is magnificent! Almost 1000 LoC, but that's necessary for maintaining data integrity and ensuring all of this is possible via both PHP an Canvas' internal HTTP API 👏

Beautiful work, @larowlan & @penyaskito!

effulgentsia’s picture

#27 reverted (I think unintentionally) my issue summary organization from #26, so I reverted back to the issue summary from #26.

effulgentsia’s picture

Issue summary: View changes

Removed the last section of the proposed resolution, some of which is outdated, and the rest a repeat of what's above it.

effulgentsia’s picture

Title: [META] Plan to allow editing props and slots for exposed code components » [META] Plan to allow editing props and slots for in-use code components
Issue summary: View changes
effulgentsia’s picture

Issue summary: View changes

.

penyaskito’s picture

Still not clear if removing a required prop is allowed. By my tests on #3567413: When editing a Canvas entity with a component tree (e.g., page, template, or region), automatically upgrade component instance versions for cases where there's no impact on existing data, it's not completely covered. Maybe we missed an issue here? Or this is deliberately not supported? What should happen then if that happens in an SDC? I might be able to answer my question looking at \Drupal\Tests\canvas\Kernel\Plugin\Canvas\ComponentSource\ComponentInputsEvolutionTest and \Drupal\Tests\canvas\Kernel\Plugin\Canvas\ComponentSource\JsComponentEvolutionTest, which I didn't yet.

lauriii’s picture

Still not clear if removing a required prop is allowed.

This should be allowed. From UX perspective it should be handled the same way as a deletion of an optional prop.

wim leers’s picture

Issue summary: View changes

#3557272: BE: Support removing a slot from a code component landed, now just needs follow-ups created.

wim leers’s picture

penyaskito’s picture

Assigned: penyaskito » Unassigned

Updated IS for #3463996: [META] [PP-1] When the field type, storage/instance settings, widget, expression or requiredness for an SDC/code component prop changes, the Content Creator must be able to upgrade. It's marked with 🟢 because the required changes for this META were done in the sub-issues (aside of changing shapes).

What's left here is 🔴 changing the shape of existing props, which still needs to be discussed., as implies potential data loss.

I'm tempted to mark both METAs as fixed, even if both have still open child issues.