`useAppMetafields` returns stringified booleans

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:

  1. The metafield can have a definition or be unstructured. I tested with a product variant metafield. It’s type must be boolean.
  2. Add a value of true or false to a variant’s metafield.
  3. 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

useappmetafield

Hi masonmcelvain,

Thanks for the detailed description of this issue - I’ve connected with the product team in this area and will report back when I learn more.

Hi again masonmcelvain,

Just wanted to update that our team are looking into this as a possible bug on our side or an issue with the documentation.

1 Like