Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

useApplyMetafieldsChange fails to update silently

useApplyMetafieldsChange fails to update silently

dylanpierce
Shopify Partner
296 14 124

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
296 14 124

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.