Overview
Follow-up to #3491459: Implement the "Review N changes" button
Chatting with @jessebaker he pointed out that if you open up a node in XB it you will immediately have it in "Review changes"
This is because in ApiPreviewController well always auto-save regardless of whether it is the same as the save version.
This could happen if you just open up the entity and preview it in XB or if do an operation, such as adding a new component or reordering components, and then select "undo" or just undo the operation manually, reseting to the saved version
Proposed resolution
Only do auto-saves for entities that are different than their saved (live) versions.
In \Drupal\experience_builder\Controller\ApiPublishAllController::__invoke we have logic to convert auto-save data to entities ready for validating/saving. We may want to move this logic into the auto-save manager(or somewhere else) so we can then compare the entities to the saved version. If there no changes to the saved versions we would then not create the auto-save entry and if there already is one delete it.
User interface changes
The mere act of previewing a content entity that contains an XB component tree no longer causes it to appear in Review changes
.
Issue fork experience_builder-3502902
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
Comment #3
tedbowComment #4
lauriiiI closed #3501939: Review changes panel shows changes even when nothing has changed as a duplicate of this. 👍
Comment #5
effulgentsia commentedComment #6
wim leersAlternatively: compute the
data_hashfor the saved entity and check if it's different.Having read
\Drupal\experience_builder\Controller\ApiLayoutController::buildPreviewRenderable()(which creates the auto-save entry for the edited content entity using client-side representation) and\Drupal\experience_builder\Controller\ApiLayoutController::get()(which computes client-side representation to boot the XB UI), it AFAICT should be possible to just compute the hash, using something like:AFAICT
\Drupal\experience_builder\Controller\ApiPublishAllController::validateExpectedAutoSaves()does not look at the saved data at all currently? So I don't think that logic helps.Comment #7
wim leersComment #8
wim leersComment #9
wim leersI think that given #3501600-23: Split 1 PageTemplate config entity into N PageRegion config entities, this is now actually a critical.
Comment #10
wim leersComment #12
tedbow@wim leers
re #6
I wasn't referring `validateExpectedAutoSaves` but I different part of what is now
\Drupal\experience_builder\Controller\ApiAutoSaveController::post.I pushed up a MR but I am not sure this idea would actually work. I added comments to the MR as to why
but here is the basic idea would be to change
\Drupal\experience_builder\AutoSave\AutoSaveManager::saveto something likeComment #13
tedbow@wim leers re #6
and your
public function hash(EntityInterface $entity, ?array $data): string {idea.This might work better than my MR but it should really have to handle all of our entity types we support because this could happen with code components or asset libraries, either because saved one was just opened in the editor and no changes were made yet or changes have been made but the user reverted those changes and now the code component or library is back to the saved state. In that case it should not be in the "Review changes" list any more
So any call to
\Drupal\experience_builder\AutoSave\AutoSaveManager::saveshouldIf we want to keep this issue to the current scope of "content entity or PageRegion" as the title suggest that might be good idea but we should think how might solve this for other types in the future.
I think with the way our front-end is you are more likely to get into this situation with content entities then say an Asset Library entity. I am not sure if auto save call from the client for the Asset Library gets called just by opening the form
Comment #14
tedbowComment #16
tedbowLeaving 3502902-doomed-idea MR open for now but I think the 3502902-create-entity-hash MR started from @wim leers idea in #6 is probably the way to go.
3502902-create-entity-hash MR is still very rough but it does solve the inital problem
When checking "Review X Changes" you have wait until the server is called again or just click to get the updates
Comment #17
wim leersInteresting how this MR seems to be touching upon/would benefit from infrastructure improvements we've been delaying to keep moving forward on features — this issue seems to be forcing us to do some of that. @tedbow specifically cited #3499632 in his MR comments.
Great to see this starting come together!
Comment #18
tedbowI reproduced the error
block-form.cy.jsmanually. The block form doesn't not work when a region besides the main contentComment #19
tedbowI haven't go block-form.cy.js passing yet.
I think what os happening is since the regions were always autosaved even if there were no changes the code path where there wasn't an auto-save probably never was tested or worked.
Manually testing if I force the region to be auto-saved in \Drupal\experience_builder\Controller\ApiLayoutController::buildPreviewRenderable then I can edit the branding block that is default placed in the header, otherwise it doesn't work.
also if put another component in the header which also triggers the region to be auto-save then I can edit both components.
So don't think it is a problem with block forms themselves it is just we only have blocks as default component in regions.
Unassigning myself but will pick it back up tomorrow
Comment #20
tedbowHopefully tests will pass now. I still need to self-review/clean-up the MR
Comment #22
tedbowComment #23
wim leersComment #26
wim leersThis simpler alternative is definitely easier to land! Especially because @larowlan sprinkled comments on the MR that walk you through what's going on 👍
Still needed:
Comment #27
wim leersWhat a rollercoaster this issue has been 😅 @tedbow did one MR, then another. Then @larowlan did a third, and explained why.
Then today, @tedbow and I iterated on @larowlan's third. Seems like @tedbow and I are mostly happy with where things are at, and @tedbow's key refactor was approved by @larowlan, and my subsequent iteration on that was approved by @tedbow, and by @larowlan. He did raise a performance concern, but I think I was able to address that adequately.
@larowlan felt that the test coverage from @tedbow's second MR didn't add much value — and while I see his point, I think there's indirect value for it, so we respectfully disagreed, but @larowlan did indicate he didn't consider it blocking 👍
Finally, 2 follow-ups were identified:
Thanks, everyone! 🚀
Comment #29
wim leersComment #31
wim leersComment #32
wim leersTo make this issue's work much more impactful: #3509270: Status badge and "Review changes" only update after ~10 seconds.
Comment #33
nagwani commented