How to make a node have a default unique ID?

like this:

attrs: {
   _id: {
        default: uuidv4(),
   }
},

but it not work

No, default attribute values are just values, they don’t get recomputed for every node. See this thread for similar discussion.

It’s not an elegant solution

Now I use other ways to solve the problem, without using ID.

Any reason for making default values as values only?

What if we allow specifying a generator like function which would compute the default whenever the node is created? Example,

attrs: {
   _id: {
        default: () => uuidv4(),
   }
},

I know this is not there in the current version. But any thoughts around support for something like this in future?

1 Like

The library had something like that at one point, but making node creation non-pure caused all kinds of awkwardness, often did the wrong thing, and still didn’t help with splitting nodes, so it was removed.