Handle upgrading and rendering not yet upgraded component instances of components with new(ly) required props that include an example value
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3568602. --> Reported by: [effulgentsia](https://www.drupal.org/user/78040) Related to !619 !563 >>> <h3 id="overview">Overview</h3> <p>Follow-up to <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3567413" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3567413</a></span>. After that issue lays the initial groundwork by handling the cases listed there, this issue is for adding support for another case:</p> <ul> <li>A Component's active version has a required prop (with an example value) that the component instance's (old) version doesn't have (i.e., a new required prop got added to the component).</li> <li>A Component's active version has a required prop (with an example value) that is an optional prop for the component instance's (old) version (i.e., an existing prop was changed from optional to required).</li> </ul> <p>Note that new(ly) required props without an example value are out of scope for this issue.</p> <p>For the cases above, we need to handle both:</p> <ul> <li>Upgrading the component instance's version when the component instance is edited (same as in <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3567413" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3567413</a></span>).</li> <li>Rendering component instances that haven't been upgraded yet (haven't been edited since the Component got changed).</li> </ul> <h3 id="proposed-resolution">Proposed resolution</h3> <p>&#128161; Baseline assumption: every required prop in a SDC/code component has &gt;=1 example value. This is guaranteed to exist because Canvas' <code>ComponentMetadataRequirementsChecker</code> requires this: otherwise the <code>Component</code> config entity would become disabled!</p> <ul> <li>Upon upgrading the component instance, add the new prop (with the above default_value) to the component instance data.</li> <li>When rendering a not-yet-upgraded component instance (component instance's version not equal to the component's active version), add the new prop (with the above default_value) to the ephemeral component instance data prior to evaluating the prop expressions. The assumption here is that because the prop is required, the component's rendering code expects it to be there.</li> </ul> <p>The first example value for the prop in its json schema becomes the <code>default_value</code> within the Component entity's <code>prop_field_definitions</code>. This is existing behavior and doesn't need to be changed.</p> <h3 id="ui-changes">User interface changes</h3> <p>Once a component is changed to have a new(ly) required prop, existing published pages will start rendering with its example value.</p>
issue