Manual sorting of plucked tags

For anyone having the same problem/idea:

Here’s my hook, I added comments so you can understand it better and adapt it to your needs/fields:

kirby()->hook('panel.page.update', function($page) {

  // Is there a "tag" field?
  if(isset($page->content()->data['tag'])) {

    // Parent page
    $parent = $page->parent();

    // Split tags
    $tags = $page->content()->get('tag')->split(";");

    // Is there a "tags" field on the parent page?
    if(isset($parent->content()->data['tags'])) {

      // Existing tags on the parent page
      $oldtags = $parent->content()->get('tags')->yaml();

      // For every tag on the updated page
      foreach($tags as $tag) {

        $n = 0;
        
        // For every existing tag on the parent page
        foreach($oldtags as $oldtag) {

          // If the tag already exists
           if($oldtag["name"] == $tag) $n++;

        }

        // If the tag doesn't exist yet
        if($n == 0) {

          // Add it to the tags array
          $oldtags[] = ['name' => $tag];
          
        }

      }

      // Update parent page
      $parent->update(array(
        'tags' => yaml::encode($oldtags)
      ));

    }
  }
});

The structure field responsible for the sorting looks like this in the blueprint:

label: Tag Order
type:  structure
fields:
  name:
    label:  Name
    type:   text

I added the following to my “panel.css” to hide the “Add” button and the “Edit” and “Delete” buttons of the structure field:

.field-name-tags .structure-entry-options, .field-name-tags .structure-add-button {
  display: none;
}
.field-name-tags .structure-entry-content {
  border-bottom: 0;
}

Everything works fine but the “loading bar” in the panel moves very slowly, for about 20 seconds. The field is updated in less than a second, but the panel seems to wait for something. If you click on something or reload the panel, the loading bar disappears. It seems like a similar issue like this one. I’m going to disable each my plugins/fields later today and see if one of them causes this “snail loading bar”.