Don't save `Component` config entities unnecessarily
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3556327. -->
Reported by: [larowlan](https://www.drupal.org/user/395439)
Related to !378
>>>
<h3 id="overview">Overview</h3>
<p>According to the <a href="https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!module.api.php/function/hook_update_N/11.x#sec_notes">rules of what you can and can't do in an update kernel</a> you should use care when writing your update function - with this being particularly relevant:</p>
<blockquote><p>In particular, loading, saving, or performing any other CRUD operation on an entity is never safe to do (they always involve hooks and services).</p></blockquote>
<p>However UpdateKernel runs with a NullBackend for discovery. So when we hit our custom ComponentPluginManager or BlockManager we're saving Component config entities if they've changed.</p>
<p>We've already seen this manifest in a couple of places:</p>
<ul>
<li><span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3550334" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3550334</a></span> - where we only got 2 versions of an SDC component in an update hook vs 3 for a JS component</li>
<li><span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3547579" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3547579</a></span> - where we thought we could use cache tags to force recalculation of storable prop shape expressions - only to discover that only worked with SDC components because of the plugin manager being invalidated - but not for JS Components</li>
</ul>
<h3 id="proposed-resolution">Proposed resolution</h3>
<ol>
<li>Only actually ever call <code>Component::save()</code> if something in a component source changed that <em>merits</em> such a save.
</li><li>Achieve that by introducing "component source discovery", as described ~6 months ago at <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3526045" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3526045</a></span>
</li><li>Check if we're in an update kernel inside ComponentPluginManager and BlockManager before saving or updating component config entities.
</li></ol>
<h3 id="ui-changes">User interface changes</h3>
<p>None.</p>
> Related issue: [Issue #3550334](https://www.drupal.org/node/3550334)
> Related issue: [Issue #3547579](https://www.drupal.org/node/3547579)
> Related issue: [Issue #3561265](https://www.drupal.org/node/3561265)
> Related issue: [Issue #3561267](https://www.drupal.org/node/3561267)
> Related issue: [Issue #3561270](https://www.drupal.org/node/3561270)
> Related issue: [Issue #3561271](https://www.drupal.org/node/3561271)
> Related issue: [Issue #3561272](https://www.drupal.org/node/3561272)
> Related issue: [Issue #3520484](https://www.drupal.org/node/3520484)
issue