Can't change subpages on a page

Hello everyone. I have a section called “Wissen” in which I plan to include articles. Should be a simple blog listing, and blog details section on the website.

Every time I try to save a new Article, or edit it, it throws a message

Storage for the page is immutable and cannot be deleted. Make sure to use the last alteration of the object.

The information is therefore saved in the _changes folder, in which I can copy manually and paste in the actual content file, and it “saves”. Is there anything that needs to be added to the blueprint to make this work? I already checked permissions in the folder, and all other pages on the website work and update well, it is only the subpages of this Wissen section.

If anyone has hints on this, I would really appreciate. Thanks! :slight_smile:

Are you using any page hooks? Or plugins that might do?

Actually I am using a site.update:after hook in the config file to check if the new site is saved with some options, and generate a slug based if a Team member is updated. But not a page specific hook.

Regarding plugins: yes, one is using a page.render:after, and another one is using a page.update:after… but it should be affecting all pages, not those ones inside Wissen section, right?

Can’t really tell without seeing what the hooks do in particular.

One is the tobimori-seo plugin. My personal hook code is below:

'hooks' => [
    'site.update:after' => function ($newSite, $oldSite) {
      if ($newSite->team()) {
        $structure = $newSite->team()->toStructure();
        $updatedItems = [];

        foreach ($structure as $item) {
          $itemData = $item->toArray();
          $name = $item->name()->value();
          $shortname = $item->shortname()->value();

          if (empty($shortname) && !empty($name)) {
            $itemData['shortname'] = Str::slug($name);
          }

          $updatedItems[] = $itemData;
        }
        
        try {
          $newSite = $newSite->update([
            'team' => yaml::encode($updatedItems)
          ]);
        } catch (Exception $e) {
          error_log('Error updating page: ' . $e->getMessage());
        }
        
        return $newSite;
      }
    }
  ]

For anyone in the future facing the same problem: I created a backup outside the Kirby folder, deleted everything, redid the structure by copying and pasting the same blueprint, with the exact same content, and it worked. I still have no clue what happened, but this is how I managed to solve it :wink:

I got the same problem, but I solved it asking ChatGPT…


Kirby CMS 5.x — Error: “Storage for the page is immutable and cannot be updated. Make sure to use the last alteration of the object.”

This happens because in Kirby 5, model objects (Page, File, Site, etc.) are immutable:
every operation that changes their state returns a new instance.

If you run an update() and then try another modification on the old $page reference, Kirby throws the error:

Storage for the page is immutable and cannot be updated. 
Make sure to use the last alteration of the object.

In addition, some instances may point to immutable storage (e.g., a version/preview copy).


:white_check_mark: How to Fix (Practical Checklist)

Always reassign the returned object

$page = $page->update(['title' => 'New title']);
$page = $page->changeSlug('new-slug');

Never call update() on a variable that still holds the “old” object.
This is a breaking change in v5.

Be careful with such AI responses without double checking the docs as well. For example, no 3 is just hallucinated nonesense.

Yes - just like any AI answer. But no.1 is correct, and it solved.

Maybe remove the hallucinated part from your post so it doesn’t get spread?

1 Like

Thanks for the reply hvsrmusic! I marked it as resolved by your solution.