With the current design of loading store configuration, in some cases, we are forced to have dependency between
loading store configuration and loading product data. With the proposal, I will give a short overview of which configuration we should load from Magento Backend. Also, how we can refactor the current state.
Currently, we only consider the Magento store configuration for the footer component https://github.com/magento/pwa-studio/blob/5542122475b834cd0ae07ee7ccda2aeb4d65d57e/packages/venia-ui/lib/components/Footer/footer.js#L7
Shop owners can change many settings by default in Magento 2, and this helped Magento to grow so fast. From my point of view, we should be taking store configuration into account to change our behaviour in PWA Studio. We already have Tickets in our backlog that are required to loading store configuration see #1940.
For that reason, it is now a good time to think about what are requirements and how we can implement this.
If I think about how often as the customer will change the store name, Copywrite, etc. then we understand this should not so often happen.
Currently, we already load only the secure media URL on build time. Loading Store Configuration on build helps
we don't need to think about cache. On every build, we
load the data from Magento.
Advantage
Disadvantages
Methode that provides the config:
The method getMediaURLneed to be refactored to getStoreConfig()
Build Config:
https://github.com/magento/pwa-studio/blob/develop/packages/venia-concept/webpack.config.js#L9
GraphQL Query:
https://github.com/magento/pwa-studio/blob/develop/packages/pwa-buildpack/lib/queries/getStoreMediaUrl.graphql
Advantage
Disadvantages:
Any chance of something like
Load store config at build time and seed it into the service worker. If it gets updated in the admin the service worker somehow (insert unknown to me wizardry here) is able to invalidate the config and retrieves the latest version?
@fooman the service worker could inspect the HTTP headers sent from the server. Once a certain header is set, reload the store config from the endpoint and cache it again. The Magento API would need to set that header only when the store config was changed.
I also think the service worker will be key here. I'm not quite sure which headers are supported right now by the graphql endpoints, but it also would be great for other usecases to have the basic headers supported that workbox is taking into account: https://developers.google.com/web/tools/workbox/modules/workbox-broadcast-update#how_are_updates_determined
These issues sound related
https://github.com/magento/pwa-studio/issues/1617
https://github.com/magento/pwa-studio/issues/1669
In our current project that's in development we load storeconfig once and save it in context so we can reuse it everywhere. We are going with the pollInterval option on useQuery so we don't have to do any redeploying.
We've made a hook called useStoreConfig() and a context that looks like
export const StoreConfigProvider = ({
children,
additionalConfig = {},
query = getStoreConfig,
}) => {
const { error, data } = useQuery(query);
if (error) {
console.error('Could not load store config', error);
}
return (
<StoreConfig.Provider
value={merge({}, defaultConfig, additionalConfig, data)}
>
{children}
</StoreConfig.Provider>
);
};
This gives us the opportunity to extend our base Storefront config easily for custom projects
@Jordaneisenburger how you handlequery dependency? StoreConfigProvider should be loaded as the first thing? Also, I think this should be supported by PWA Studio out of the box. For those reasons, I was writing this :smile_cat:
Yeah you can do something like this in your src/index.js i think something like this is what pwa studio could also provide out of the box indeed.
<StoreConfigProvider
query={storeConfig}
additionalConfig={{
feedbackCompanySummary: {
link: '',
name: '',
score: '',
score_max: '',
total_reviews: '',
},
deliveryTimeLabel: {
label: '',
},
}}
>
Nice details @larsroettig
At the initial looks of it, StaleWhileRevalidate strategy in the SW for the store config will address the issue at hand.
We can couple this along with bundle time fetch as well if needed.
Most helpful comment
Yeah you can do something like this in your
src/index.jsi think something like this is what pwa studio could also provide out of the box indeed.