My theme app extension app block on product page is powered by Gadget. The extension should show only for certain products (stored in my gadget table which has a many to many relationship with shopifyProduct). For all other products, the app block must render null - i.e. not download the gadget web.min.js file and other scripts needed to render the app block (Page Speed for the Win!!!).
The way to solve this is by creating a new metafield on product and in the liquid code add an if condition that checks product.metafield.shouldShowMyAppBlock === true and renders the app block code only if its true.
But I'm afraid this could be an anti-pattern. Here's why - every time the merchant interacts with my app, I create a model action that calls the Shopify Metafields API. Ideally, all of that logic stays in Gadget as there is fewer chances of things going wrong like errors with Shopify API, network issues, race conditions, etc.
Someone with experience can tell me if I'm thinking about this wrong and there isnt' a need to worry as this is the canonical way of doing it.
So, is this an anti-pattern or is the metafields approach ok?