useApplyMetafieldsChange fails to update silently

dylanpierce
Shopify Partner
215 3 99

Hello,

We've noticed a bug with attempting to apply order metafields in Checkout UI Extensions.

Applying a metafield change during checkout where a metafield value is already present will result in a false positive result.

Here's a snippet of example code:

```

applyMetafieldsChange({
type: "updateMetafield",
key: "check_id",
namespace: "real_id",
value: check.id,
valueType: "string",
})
.then(() => {
console.log("Updated real_id.check_id metafield to : ", check.id);
console.log(
"Result: ",
metafields.find((mf) => mf.key == "check_id")?.value
);
})
.catch((e) => {
console.error(`Failed to update metafield`);
console.error(e);
});

```

 

If `check_id` in this example is `bbbbbbb` for example, then you'd expect the result to be `bbbbbbb`. Yet, we're seeing this strange output from this code above:

```
Updated real_id.check_id metafield to : bbbbbbb
Result: aaaaaaa
```
It appears the `applyMetafieldsChange` doesn't actually properly update the metafield nor does it throw an error in this case when the update failed.

Is there a special flag that needs to be passed to "force" an update?

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.

Reply 1 (1)

dylanpierce
Shopify Partner
215 3 99

I've also created a bug report on the Shopify UI Extensions Github Repository.

Here's a link to the issue: https://github.com/Shopify/ui-extensions/issues/1912

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.