Cannot fetch shop metafield on the theme editor preview

Hi there,

I have created a customer account ui extension for my app but nothing is rendered on the theme editor (it works correctly on the online store)

My extension fetches a shop metafield and then renders a form based on this metafield. On the online store it is able to fetch that shop metafield while on the theme editor it cannot

  async function fetchAccountForm() {
    return await fetch("shopify://customer-account/api/2024-10/graphql.json", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ query: getAccountFormMetafieldQuery }),
    });
  }

Shouldn’t it works on the theme editor too?

I’ve found that the hook useExtensionEditor() returns {type: checkout} when you are on the theme editor, otherwise it returns undefined

For now, I will display a dummy preview of my extension on the theme editor as workaround

Hi! I believe that you’re referring to the Checkout and Customer Accounts Editor?

In the context of the Editor, responses to Customer Account API requests are mocked which is why you’re not getting any results on your metafield queries.

As you mentioned, I believe a dummy preview would be the best approach in this case.

2 Likes