@W-18172401 Integrate getUrlMapping on server-side navigation#2290
@W-18172401 Integrate getUrlMapping on server-side navigation#2290hajinsuha1 wants to merge 192 commits intofeature/extensibility-v2from
Conversation
packages/pwa-kit-react-sdk/src/ssr/universal/components/route-component/index.js
Outdated
Show resolved
Hide resolved
| module.exports = { | ||
| app: { | ||
| extensions: [ | ||
| ['@salesforce/extension-commerce-bm-seo', {}], |
There was a problem hiding this comment.
the order in which extension-commerce-bm-seo does not matter anymore for the server-side navigation to work
There was a problem hiding this comment.
@hajinsuha1 But I think we'll want the seo extension to be first, though. So that other extensions after it can reuse the Auth object.
| // Local Imports | ||
| import {Config} from '../types' | ||
|
|
||
| export const getShopperSeoClient = async (locals: Record<string, any>, config: Config) => { |
There was a problem hiding this comment.
@bendvc @vmarta wanted to check in if we're okay going forward with this approach of pulling in ShopperSeo directly from commerce-sdk-isomorphic. This is because we need to make the API call in getRoutesAsync which is outside the HOC. On lines 24-31 it also looks like we handle saving the Auth in locals so we don't recreate it each time.
I think this means the SEO extension requires the commerceApi to be defined in the config unlike chakra-store-locator
There was a problem hiding this comment.
@hajinsuha1 I don't know if there's another way to do it. Our commerce-sdk-react does not provide us with a non-react way to get the api client. So we would have to rely on the underlying sdk-isomorphic lib.
To minimize the impact, we still wanted to use the Auth class from commerce-sdk-react, since that's one of the main benefits to using that library.
vmarta
left a comment
There was a problem hiding this comment.
I'll continue to review this PR, in particular the files in the SEO extension.
| ...route, | ||
| componentName: route.component.displayName | ||
| componentName: route.component.displayName, | ||
| ...(route.componentProps && {componentProps: route.componentProps}) |
There was a problem hiding this comment.
@hajinsuha1 I'm seeing a typescript error on this line:
Property 'componentProps' does not exist on type 'RouteProps<string, { [x: string]: string | undefined; }>'. (tsserver 2339)
Which makes the pwa-kit-extension-sdk package unable to build successfully.
| } | ||
| }, | ||
| "commerceAPIAuth": { | ||
| "propertyNameInLocals": "commerceAPIAuth" |
There was a problem hiding this comment.
@hajinsuha1 if you want to hardcode it, perhaps we should make the property name more unlikely to collide → something like __commerceAPIAuth.
| export const getAppOrigin = ( | ||
| locals: Record<string, any> = {}, | ||
| fromXForwardedHeader = false | ||
| ): string => { | ||
| if (typeof window !== 'undefined') { | ||
| return window.location.origin | ||
| } | ||
|
|
||
| const xForwardedOrigin = locals.xForwardedOrigin | ||
| if (fromXForwardedHeader && xForwardedOrigin) { | ||
| return xForwardedOrigin | ||
| } | ||
|
|
||
| const {APP_ORIGIN = ''} = process.env | ||
| return APP_ORIGIN | ||
| } |
There was a problem hiding this comment.
@hajinsuha1 I think so. Currently getAppOrigin has this older implementation, and I'm not sure why it's being deprecated.
pwa-kit/packages/pwa-kit-react-sdk/src/utils/url.js
Lines 23 to 37 in 6cfecf0
| // Local Imports | ||
| import {Config} from '../types' | ||
|
|
||
| export const getShopperSeoClient = async (locals: Record<string, any>, config: Config) => { |
There was a problem hiding this comment.
@hajinsuha1 I don't know if there's another way to do it. Our commerce-sdk-react does not provide us with a non-react way to get the api client. So we would have to rely on the underlying sdk-isomorphic lib.
To minimize the impact, we still wanted to use the Auth class from commerce-sdk-react, since that's one of the main benefits to using that library.
| module.exports = { | ||
| app: { | ||
| extensions: [ | ||
| ['@salesforce/extension-commerce-bm-seo', {}], |
There was a problem hiding this comment.
@hajinsuha1 But I think we'll want the seo extension to be first, though. So that other extensions after it can reuse the Auth object.
| * is configured with, including those defined in the base application and those added by all the extensions. You can use this | ||
| * method to modify these routes in any way you want, but you must return an array of routes as a result. | ||
| */ | ||
| beforeRouteMatch({allRoutes}: BeforeRouteMatchParams): RouteProps[] { |
| { | ||
| path: requestURL.pathname, | ||
| component, | ||
| componentProps: props, |
There was a problem hiding this comment.
@hajinsuha1 just an aside: sometimes I feel you have important comments made in Github PR that I think it's best if they're written as code comments instead. Such comments in Github would be easily lost/forgotten.
…om pwa-kit-react-sdk
…SalesforceCommerceCloud/pwa-kit into implement-dynamic-update-routes
This reverts commit ade541e.
…31976@) (#2390) * Remove extension prefix * Clean changes in template-typescript-minimal * Optimize detecting extensions logic * WIP Fix tests * Fix tests * Fix tests * Move import constant * Refactor packagePath ternary * Condensed fullPackagePath into one line * Update package namespace and name extract logic * Use validate-npm-package-name in generator * lint * Adjust generator copy * Update packages/pwa-kit-create-app/scripts/create-mobify-app.js Co-authored-by: Kevin He <kevin.he@salesforce.com> Signed-off-by: Adam Raya <adamraya@users.noreply.github.com> * PR Feedback detectExtensions args --------- Signed-off-by: Adam Raya <adamraya@users.noreply.github.com> Co-authored-by: Kevin He <kevin.he@salesforce.com>
…SalesforceCommerceCloud/pwa-kit into implement-dynamic-update-routes
This reverts commit 1d524d1.

Description
Types of Changes
Changes
extension-seo-url-mappingextensionextendRoutesmethod to make a Shopper SEOgetUrlMappingAPI call and add it to the routes if a response is returnedpwa-kit-react-sdkto serialize and deserialize routes to allow dynamically modifying the routes listHow to Test-Drive This PR
New Arrivalscategory is renderedPlatinum Blue Stripes Easy Care Fitted Shirtproduct is rendered/category/top-sellersChecklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization