Overview

When you send a PATCH request to the experience_builder.api.config.patch route, it (via experience_builder_entity_update()) deletes the version that's in auto-save storage, which is correct since that's now outdated. However, sometimes what we want instead is to apply the same set of changes to both the published entity and to the auto-saved one. For example, in #3513147: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version, we want to set status=1 to both the published js_component and the auto-saved one, while neither deleting the auto-saved one nor publishing the other changes that are in the auto-saved one. The reason we want that is setting status=1 needs to trigger the creation of the corresponding component entity, but it should only do that when the entity is saved for real.

A way to think of this is: we want to apply a "hot fix" to both the production branch (the published entity) and the development branch (the auto-saved draft).

Proposed resolution

Proposal by @wimleers
See #4 + #5.

Implemented in https://git.drupalcode.org/project/experience_builder/-/merge_requests/937 and passing tests.

Original proposal by @effulgentsia
We already have these two routes:
  • experience_builder.api.config.patch
  • experience_builder.api.config.auto-save.patch

Create a 3rd route, (what's a good name: experience_builder.api.config.published-and-auto-save.patch? experience_builder.api.config.hotfix.patch?), that applies the PATCH body to both.

User interface changes

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

effulgentsia created an issue. See original summary.

effulgentsia’s picture

Issue summary: View changes
effulgentsia’s picture

Issue summary: View changes
wim leers’s picture

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

How do we know which config entity properties this is safe to do for?

Would it be okay to start with only status? 🙏

A way to think of this is: we want to apply a "hot fix" to both the production branch (the published entity) and the development branch (the auto-saved draft).

Helpful metaphor 👍

Create a 3rd route

Why? Why not:

diff --git a/src/Controller/ApiConfigControllers.php b/src/Controller/ApiConfigControllers.php
index e308597fe..c489692e3 100644
--- a/src/Controller/ApiConfigControllers.php
+++ b/src/Controller/ApiConfigControllers.php
@@ -182,6 +182,7 @@ final class ApiConfigControllers extends ApiControllerBase {
     }
 
     // Save the XB config entity, respond with a 200.
+    // @todo Also update the auto-save version with the changed fields. Do this using a \Drupal\Core\Config\ConfigEvents::SAVE subscriber.
     $xb_config_entity->save();
     $xb_config_entity_type = $xb_config_entity->getEntityType();
     assert($xb_config_entity_type instanceof ConfigEntityTypeInterface);
wim leers’s picture

Assigned: effulgentsia » wim leers
Status: Postponed (maintainer needs more info) » Active
Issue tags: +sprint

Crafting a draft MR.

Another reason to do what I proposed in #4 is to prevent auto-saves being wiped when updating config through some other way (e.g. CLI upload tool or perhaps even config sync): imagine that the label of a JavaScriptComponent config entity is modified by the config sync, then you don't want to lose your auto-saved changes to the actual JS code.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Active » Needs work

Outline of MR pushed.

wim leers’s picture

What I'm proposing is essentially a subset of #3492059: [META] Conflict-free concurrent editing.

wim leers’s picture

Title: Add a route for PATCHing both a config entity and its auto-saved version together » Modifying a XB config entity's `status` or `label` should update the auto-save entry too, rather than delete it
Category: Task » Feature request
Priority: Normal » Major
Status: Needs work » Needs review
Issue tags: +Needs issue summary update
Related issues: +#3513147: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version

wim leers’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update +blocker
wim leers’s picture

Assigned: Unassigned » tedbow

Confirmed by @hooroomoo at #3513147-13: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version that this fixes the problem. (But there's another bug they surface there. So we can't merge this until @hooroomoo clarifies at #3513147-14: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version how to reproduce that bug.)

Needs sign-off from an auto-save maintainer. @larowlan is out, so @tedbow, over to you!

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

tedbow’s picture

Assigned: tedbow » Unassigned
Status: Needs review » Reviewed & tested by the community

Looks good! will merge on green tests

wim leers’s picture

Quoting #12:

(But there's another bug they surface there. So we can't merge this until @hooroomoo clarifies at #3513147-14: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version how to reproduce that bug.)

hooroomoo’s picture

So just to preface, all my testing has been with sending PATCH requests to /xb/api/config/js_component/${id}, not the auto-save because that's what's currently in the code.

Could you confirm if client side PATCH requests to change the status or the label should still be sent to /xb/api/config/js_component/${id} or does it need to change to send it to /xb.api/config/auto-save/js_component/${id}?

1. WITHOUT frontend change
This issue I was seeing on this MR (with no frontend changes) turned out to also exist in 0.x. The bug (let's call this Bug #1) is

  1. Create and add a code component to your library (using top right Add to components button in code editor)
  2. Add component to your page preview
  3. Make an edit to the code from the library
  4. Exit out of the code editor
  5. All the styling (CSS) is gone from the component in the page preview.

Since the bug also exists in 0.x, that means this MR is not the cause of it.

2.) WITH frontend change to PATCH request to only send necessary changes.(Currently in 0.x, PATCH requests are still sending the entire component )

  1. Create a new code component
  2. Trigger an auto-save and then click "Add to components" from the top right in the code editor
  3. Add the component to your page preview. It doesn't render anything.
  4. If you look in your /sites/default/files/astro-island nothing is generated from your newly created code component

This behavior exists on both 0.x and this MR, WITH the frontend change to the PATCH request of only sending wanted changes.
----------------------------------------

So my conclusion: I don't think merging in this MR will cause any regressions that don't already exist in 0.x, However, I think we should open a ticket for the frontend updating its PATCH requests to only send wanted changes and also with help from the backend to figure out bug #2 - why aren't the compiled files being generated when the PATCH request body changes?

wim leers’s picture

Could you confirm if client side PATCH requests to change the status or the label should still be sent to /xb/api/config/js_component/${id} or does it need to change to send it to /xb.api/config/auto-save/js_component/${id}?

The answer depends:

  • If you need the changes to first appear under "view changes" prior to publishing everything together: /xb/api/config/auto-save/js_component/…
  • If you need the changes to NOT first appear there but be "immediate" (e.g. the "add to components" button), then: /xb/api/config/js_component/…
wim leers’s picture

Assigned: Unassigned » tedbow
Status: Reviewed & tested by the community » Needs review

@tedbow If you have time, could you please investigate #16?

tedbow’s picture

Investigating

tedbow’s picture

tedbow’s picture

Assigned: tedbow » hooroomoo

For #16.2 I think we figured out that it is NOT an issue with the current MR.

which makes sense because in 0.x we would be deleting the auto-saved entry of the component if you just sent the status, while in 0.x we would just updating the status in the auto-save entry

@hooroomoo can you confirm?

hooroomoo’s picture

I think the issue i was seeing in 16.2 had to do with my css aggregation being on or something else weird because I tested it again with css aggregation OFF, and I'm able to correctly see the autosaved component in my page preview. Also renders correctly after publishing.

I think this MR is good to go. I added the frontend changes to change the PATCH request to only send wanted changes and it works as expected.

This MR should fix both:

#3513147: Using actions from the contextual menu from the sidebar list overrides code component with its latest non-autosaved version #3520698: Cannot add component to the component library using the contextual menu

hooroomoo’s picture

Assigned: hooroomoo » Unassigned
effulgentsia’s picture

Status: Needs review » Needs work

This looks good to me, but there's a failing E2E test that looks like it could be related to this MR, not just a flaky test.

hooroomoo’s picture

I've seen the same assertion fail on different MRs as well as on 0.x so I think it might just be the flaky test and there was an issue filed for it #3520830: Cypress test publish-validation is flaky.

The fail is definitely unrelated to the frontend change. But maybe @tedbow could confirm if the fail is unrelated to the backend changes

hooroomoo’s picture

Issue tags: +Needs reroll

experience_builder.auto_save.inc doesn't exist in 0.x anymore since #3517636: Move to OO hooks now we require 11.x got in so this needs a rebase

hooroomoo’s picture

Assigned: Unassigned » tedbow
tedbow’s picture

re #24 and #25 I ran the failing tests locally on 0.x and the MR branch.

publish-validation.cy.js consistently passes for me locally on both branches

component-operations.cy.js consistently passes for me on 0.x and consistently fails on the MR branch 😢. I haven't looked into why yet

@hooroomoo have you run the tests locally? Would be good to double check if someone else gets the same result

tedbow’s picture

Assigned: tedbow » hooroomoo
hooroomoo’s picture

Assigned: hooroomoo » tedbow

Assigning back to @tedbow to fix the merge conflicts with 0.x and hoping for a successful test run post-rebase since some test improvements got into 0.x this morning

wim leers’s picture

Assigned: tedbow » wim leers

I'll tackle that since I worked on #3517636: Move to OO hooks now we require 11.x.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
Parent issue: » #3521002: [META] Maintainable client-side data model + internal HTTP API

The e2e test failures have been fixed in #3521730: Make the current crop of fussy tests less difficult.

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Merging given the approvals by @hooroomoo and @tedbow — thanks both of you for the intense collaboration on this issue cluster! 😄🙏

  • wim leers committed e72f0d0b on 0.x
    Issue #3519634 by wim leers, tedbow, hooroomoo, effulgentsia, larowlan:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

effulgentsia’s picture

Issue tags: -sprint