SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
276 stars 126 forks source link

@W-15907094@ Refactor /mobify paths #1824

Closed vcua-mobify closed 3 weeks ago

vcua-mobify commented 1 month ago

In preparation of upcoming work to support namespaces for /mobify routes, we are consolidating the places where /mobify routes are hard coded in the monorepo. This will enable us to make concise changes in the future.

Change Summary:

Testing the changes:

Note:

Next steps: There will be a subsequent PR to implement the getNamespace() function introduced in this PR. For now, getNamespace returns a blank string, which results in all /mobify routes still applying to root (unchanged from existing behaviour).

Going a bit into what this future PR might look like:

The namespace is likely to be defined in the config files via a property or a function. By allowing the namespace to be a function, we can do something like the following inside a .js config file

module.exports = {
    app: {
        defaultSite: 'RefArchGlobal',
        siteAliases: {
            RefArch: 'us',
            RefArchGlobal: 'global'
        },
        ...
    },
    ssrNamespace: () => {
        const config = this
        return config.app.siteAlias[config.app.defaultSite]
    },
   ...

This allows projects to define how they want to set the namespace without config.app details bleeding into pwa-kit-runtime. Thanks @bendvc for the suggestion on this!