Updating page when it is open in the panel - losing changes

When I update a page field (using a hook) and I have the page open in the panel at the same time, the changes are only saved if I click revert in the orange bar that comes up. Is there anyway around this?

Which Kirby version are you using? You mean the changes that you make programmatically are only saved when you click revert or the changes you make in the Panel?

I don’t know if the lock feature should prevent that automatically or if you have to check in your code if the page is locked.

I am on the latest version (not RC).

You mean the changes that you make programmatically are only saved when you click revert or the changes you make in the Panel?

Yes - the programmatically changed fields do not show, unless I press revert, if I press save the changes are lost

Saving the page after the update, seems to have sorted it:

$page->save();