Snapshots or version control are created when you save the view, but this always saves even if there are no changes to the view itself.
Save the view and create the new version of it
Create a validator to compare what is saved with the active configuration to see if there are changes, so that a new version can be created in version control.
One possible improvement for handling this could be leveraging Drupal’s core configuration diff functionality to determine whether there are actual changes before creating a new snapshot.
Drupal already provides a way to compare configuration objects using the Diff/ConfigDiffer approach, which can help avoid creating snapshots when there are no meaningful differences.
For example, something along these lines could be used in a service or pre-save check:
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\MemoryStorage;
$active_storage = \Drupal::service('config.storage');
$snapshot_storage = new MemoryStorage();
$comparer = new StorageComparer($snapshot_storage, $active_storage);
if (!$comparer->createChangelist()->hasChanges()) {
// No real configuration changes detected, skip snapshot creation.
}
This might help ensure snapshots are only created when there are actual configuration differences, instead of on every save action.
Comments
Comment #2
josecarlosmedero commentedHi
I was able to reproduce the issue in my environment.
Environment:
Drupal: 11.3
Module version: 1.0.0
Steps to reproduce:
Go to any existing View configuration.
Do not make any changes.
Click “Save”.
Go to the snapshot/history list.
Actual result:
A new snapshot is created even though no changes were made compared to the previous one.
Expected result:
No new snapshot should be created if there are no configuration changes.
Comment #3
josecarlosmedero commentedOne possible improvement for handling this could be leveraging Drupal’s core configuration diff functionality to determine whether there are actual changes before creating a new snapshot.
Drupal already provides a way to compare configuration objects using the Diff/ConfigDiffer approach, which can help avoid creating snapshots when there are no meaningful differences.
For example, something along these lines could be used in a service or pre-save check:
This might help ensure snapshots are only created when there are actual configuration differences, instead of on every save action.
Comment #4
rogelio1992 commented