-
Notifications
You must be signed in to change notification settings - Fork 214
@W-17543649 - [SEO] Before calling getUrlMapping check the React Router Config first
#2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
bf3dc89
try using matchpath for allowlisting
yunakim714 ee053db
skip geturlmapping api call if path is found
yunakim714 75104c5
read config value matchingStrategy
yunakim714 330f896
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 060f04d
add config to default json
yunakim714 034834d
revert package lock
yunakim714 eb3159e
lint
yunakim714 6280b64
lint
yunakim714 a08eaaa
setup jest and add test cases
yunakim714 150fb0c
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 7f350dc
refactor seo to resolve react errors
yunakim714 a67efe3
Merge branch 'W-17543649-seo-allowlist-routes' of github.com:Salesfor…
yunakim714 047b4ac
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 c5db1a0
lint
yunakim714 a308fb1
fix matching logic
yunakim714 4c5e397
add comments, exit early
yunakim714 f836d94
update config naming
yunakim714 84214ea
fix naming
yunakim714 a6e6240
add config details in readme
yunakim714 89e73a4
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 b0d54cc
add warning if there are multiple wildcard routes
yunakim714 ddd8641
Merge branch 'W-17543649-seo-allowlist-routes' of github.com:Salesfor…
yunakim714 324b91f
move to correct readme file, add sample.json
yunakim714 6f73931
resolve merge conflicts
yunakim714 c759e50
resolve merge conflicts
yunakim714 365615b
resolve merge conflicts
yunakim714 2634f86
resolve merge conflicts
yunakim714 67e146a
move matchPath function to utils module
yunakim714 a812e24
add tests for matchpath
yunakim714 71f5c40
Fix tests
jeremy-jung1 bbc7563
Merge branch 'W-17543649-seo-allowlist-routes' of github.com:Salesfor…
jeremy-jung1 91d604b
cleanup
yunakim714 bd7762c
Merge branch 'W-17543649-seo-allowlist-routes' of github.com:Salesfor…
jeremy-jung1 e0d9221
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 5cf882f
cleanup
yunakim714 98aa1d9
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 5dcf5c6
resolve merge conflicts
yunakim714 23075cd
update package-lock
yunakim714 ba5a6f4
fix useblock test
yunakim714 6093098
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 66d3228
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 34fd298
fix comments and add test case
yunakim714 f6a0bc3
log warning for undefined paths
yunakim714 2f16eff
address comments
yunakim714 a0d4b18
remove console log
yunakim714 610912b
change matchpath return type
yunakim714 acea559
cleanup
yunakim714 b7a593f
Merge branch 'useBlock' into W-17543649-seo-allowlist-routes
yunakim714 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "enabled": true, | ||
| "routingMode": "api_first", | ||
| "commerceApi": { | ||
| "proxyPath": "/mobify/proxy/api", | ||
| "parameters": { | ||
| "shortCode": "8o7m175y", | ||
| "clientId": "c9c45bfd-0ed3-4aa2-9971-40f88962b836", | ||
| "organizationId": "f_ecom_zzrf_001", | ||
| "siteId": "RefArchGlobal" | ||
| } | ||
| }, | ||
| "resourceTypeToComponentMap": { | ||
| "category": "ProductList", | ||
| "product": "ProductDetail", | ||
| "content_asset": "ProductList" | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| export const ROUTING_MODE = { | ||
| ROUTER_FIRST: 'router_first', | ||
| API_FIRST: 'api_first' | ||
| } | ||
yunakim714 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
40 changes: 40 additions & 0 deletions
40
packages/extension-commerce-bm-seo/src/utils/route-match-utils.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright (c) 2025, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import {matchPath} from './route-match-utils' | ||
|
|
||
| describe('matchPath', () => { | ||
| const NullComponent = () => null | ||
| const routes = [ | ||
| {path: '/', component: NullComponent}, | ||
| {path: '/about', component: NullComponent}, | ||
| {path: '/contact', component: NullComponent}, | ||
| {path: '/products/*', component: NullComponent}, | ||
| {path: '/products/:id', component: NullComponent}, | ||
| {path: '*', component: NullComponent} | ||
bendvc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
|
|
||
| it('should return the matching route', () => { | ||
| const result = matchPath('/about', routes) | ||
| expect(result).toEqual({path: '/about', component: NullComponent}) | ||
| }) | ||
|
|
||
| it('should return the matching route with wildcard if filterWildcardRoutes is false', () => { | ||
| const result = matchPath('/products/123', routes) | ||
| expect(result).toEqual({path: '/products/*', component: NullComponent}) | ||
| }) | ||
|
|
||
| it('should return the matching route without wildcard if filterWildcardRoutes is true', () => { | ||
| const result = matchPath('/products/123', routes, {filterWildcardRoutes: true}) | ||
| expect(result).toEqual({path: '/products/:id', component: NullComponent}) | ||
| }) | ||
|
|
||
| it('should return undefined if no match is found and filterWildcardRoutes is true', () => { | ||
| const result = matchPath('/none', routes, {filterWildcardRoutes: true}) | ||
| expect(result).toBeUndefined() | ||
| }) | ||
| }) | ||
43 changes: 43 additions & 0 deletions
43
packages/extension-commerce-bm-seo/src/utils/route-match-utils.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
yunakim714 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Copyright (c) 2025, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import {matchPath as matchPathReactRouter} from 'react-router-dom' | ||
| import {RouteProps} from '@salesforce/pwa-kit-extension-sdk/types' | ||
|
|
||
| /** | ||
| * Checks whether the given URL path matches a predefined route defined in the application's routes config. | ||
yunakim714 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Optionally filters out wildcard routes and warns if multiple wildcard routes are detected. | ||
| * @param pathname - The URL path to check | ||
| * @param routes - Array of route configurations to check against | ||
| * @param options - Optional configuration for filtering wildcard routes | ||
| * @returns The matching route object or undefined if no match is found | ||
| */ | ||
| export const matchPath = ( | ||
| pathname: string, | ||
| routes: RouteProps[], | ||
| options?: {filterWildcardRoutes: boolean} | ||
| ): {path: string} | undefined => { | ||
| let validRoutes = routes | ||
| // Filter out routes ending with a wildcard if the option is set | ||
| if (options?.filterWildcardRoutes) { | ||
| const wildcardRoutes = routes.filter((route) => route.path.endsWith('*')) | ||
| if (wildcardRoutes.length > 1) { | ||
| console.warn( | ||
| `Multiple wildcard routes detected (${wildcardRoutes.length}). This may cause unexpected routing behavior. Wildcard routes:`, | ||
| wildcardRoutes.map((route) => route.path) | ||
| ) | ||
| } | ||
| validRoutes = routes.filter((route) => !route.path.endsWith('*')) | ||
| } | ||
|
|
||
| const routeMatch = validRoutes.find(({path}) => | ||
| matchPathReactRouter(pathname, { | ||
| path, | ||
| exact: true | ||
| }) | ||
| ) | ||
| return routeMatch | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ describe('useBlockNavigation', () => { | |
|
|
||
| it('should call the callback and push navigation after callback resolves', async () => { | ||
| const callback = jest.fn().mockResolvedValue(undefined) | ||
| render(<TestComponent callback={callback} />) | ||
| const {unmount} = render(<TestComponent callback={callback} />) | ||
|
||
|
|
||
| // Simulate navigation to a new location | ||
| await act(async () => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.