Reposting this issue here as requested in [IMPORTANT] Stop creating issues here, use the Shopify Community forum instead · Issue #2521 · Shopify/ui-extensions · GitHub
Please list the package(s) involved in the issue, and include the version you are using
@shopify/ui-extensions-react@2024.1.1
Describe the bug
useAppMetafields returns the values "true" and "false" for boolean metafields instead of true and false. This is surprising because AppMetafield.value’s type definition includes boolean.
// https://github.com/Shopify/ui-extensions/blob/c22cbdaf0b3bcc887aa554c30bfdbcdeb4d96750/packages/ui-extensions/src/surfaces/checkout/api/standard/standard.ts#L178-L196
/**
* Represents a custom metadata attached to a resource.
*/
export interface AppMetafield {
/** The key name of a metafield. */
key: string;
/** The namespace for a metafield. */
namespace: string;
/** The value of a metafield. */
value: string | number | boolean;
/** The metafield’s information type. */
valueType: 'boolean' | 'float' | 'integer' | 'json_string' | 'string';
/** The metafield's type name. */
type: string;
}
Steps to reproduce the behavior:
- The metafield can have a definition or be unstructured. I tested with a product variant metafield. It’s type must be
boolean. - Add a value of
trueorfalseto a variant’s metafield. console.log(useAppMetafields({ id: yourMetafieldId }))produces a value similar to the screenshot below.
Expected behavior
AppMetafield.value should be a boolean if the type of the metafield is boolean, not "true" or "false".
Screenshots
