-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
What problem does this address?
Blocks cannot use attributes to store information that is unique internal to the block instance but also persisted across page loads. Here's an illustrative example:
I'm working on the Jetpack Pay with PayPal
block. It contains a productId
attribute which uniquely identifies the actual product record referenced by the block. When a new block is inserted this attribute will be undefined; we hit the API to create a new product, and store the returned id in this attribute.
When the block is duplicated, I'd like to create a new product record with identical fields (title/price/etc). But because the productId
is cloned along with all the other attributes, both blocks will point to the same resource. It's possible to keep track of the block's unique clientId
and reset the product when this value changes — but while this detects block duplication, it also changes every time the post loads, and I only want to reset the product on duplication.
What is your proposed solution?
A couple of options as a starting point for discussion:
- Add support for
unique
internal
attributes, which do not get copied during block duplication. - Allow blocks to listen for/handle the duplication event.