Metafields appears to be stale when accessed in theme app extension intermittently

We currently set several metafields on the Shop object to store configuration that is used in our theme app extension. Recently we’ve been seeing issues where we keep setting the metafields and if you access the value through getMetafields it’s changed. However when accessing it through liquid in the theme app extension we get a stale value for a long time.

The only solution we have found is to unset the metafield and set it again. This however can lead to issues for the app where it won’t have access to data for a short while when it’s unset.

{%- if shop.metafields.restockrocket_$ENVIRONMENT.selling_plans -%}

    window._RestockRocketConfig.sellingPlans = {{ shop.metafields.restockrocket_$ENVIRONMENT.selling_plans }};

{%- else -%}

window._RestockRocketConfig.sellingPlans = [];

{%- endif -%}