Prevent a user to create two identical items in a structure field

If I change

'page.update:before' => function ($page, $values, $strings) {

to

'page.update:after' => function ($page, $values, $strings) {

I get this error from panel:
Exception: ArgumentCountError
Too few arguments to function Kirby\Cms\App::{closure}(), 2 passed and exactly 3 expected.

And If I change to:

'page.update:after' => function ($page) {

Nothing happen on save…