-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop-6.5.x' into epic/opf
- Loading branch information
Showing
228 changed files
with
7,888 additions
and
1,200 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
name: Cache node modules | ||
|
||
env: | ||
NODE_VERSION: '16' | ||
NODE_VERSION: '18' | ||
|
||
jobs: | ||
cacheNodeModules: | ||
|
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
set -e | ||
|
||
export SPA_ENV='lighthouse' | ||
export NODE_OPTIONS=--dns-result-order=ipv4first | ||
|
||
npm install -g @lhci/[email protected] | ||
|
||
|
This file contains 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 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 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
16 changes: 16 additions & 0 deletions
16
core-libs/setup/ssr/optimized-engine/rendering-strategy-resolver-options.ts
This file contains 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,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export interface RenderingStrategyResolverOptions { | ||
excludedUrls?: string[]; | ||
excludedParams?: string[]; | ||
} | ||
|
||
export const defaultRenderingStrategyResolverOptions: RenderingStrategyResolverOptions = | ||
{ | ||
excludedUrls: ['checkout', 'my-account', 'cx-preview'], | ||
excludedParams: ['asm'], | ||
}; |
62 changes: 62 additions & 0 deletions
62
core-libs/setup/ssr/optimized-engine/rendering-strategy-resolver.spec.ts
This file contains 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,62 @@ | ||
/// <reference types="jest" /> | ||
|
||
import { RenderingStrategy } from './ssr-optimization-options'; | ||
import { Request } from 'express'; | ||
|
||
import { defaultRenderingStrategyResolver } from './rendering-strategy-resolver'; | ||
|
||
describe('RenderingStrategyResolver', () => { | ||
let resolver: (req: Request) => RenderingStrategy = | ||
defaultRenderingStrategyResolver({ | ||
excludedUrls: ['checkout', 'my-account'], | ||
excludedParams: ['asm'], | ||
}); | ||
|
||
it('should return DEFAULT rendering strategy if no excluded parameters or URLs match', () => { | ||
const request: Partial<Request> = { | ||
query: {}, | ||
url: '/some-page', | ||
}; | ||
|
||
const strategy = resolver(request as Request); | ||
|
||
expect(strategy).toBe(RenderingStrategy.DEFAULT); | ||
}); | ||
|
||
it('should return ALWAYS_CSR rendering strategy if an excluded parameter matches', () => { | ||
const request: Partial<Request> = { | ||
query: { | ||
asm: 'true', | ||
}, | ||
url: '/some-page', | ||
}; | ||
|
||
const strategy = resolver(request as Request); | ||
|
||
expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR); | ||
}); | ||
|
||
it('should return ALWAYS_CSR rendering strategy if the URL matches an excluded URL', () => { | ||
const request: Partial<Request> = { | ||
query: {}, | ||
url: '/checkout/confirm', | ||
}; | ||
|
||
const strategy = resolver(request as Request); | ||
|
||
expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR); | ||
}); | ||
|
||
it('should return ALWAYS_CSR rendering strategy if both excluded parameters and URLs match', () => { | ||
const request: Partial<Request> = { | ||
query: { | ||
asm: 'true', | ||
}, | ||
url: '/checkout/confirm', | ||
}; | ||
|
||
const strategy = resolver(request as Request); | ||
|
||
expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
core-libs/setup/ssr/optimized-engine/rendering-strategy-resolver.ts
This file contains 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,64 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { RenderingStrategy } from './ssr-optimization-options'; | ||
import { RenderingStrategyResolverOptions } from './rendering-strategy-resolver-options'; | ||
|
||
const hasExcludedParams = ( | ||
request: Request, | ||
excludedParams: string[] | undefined | ||
): boolean => { | ||
const params: string[] = request.query | ||
? Object.getOwnPropertyNames(request.query) | ||
: []; | ||
|
||
if (!excludedParams) { | ||
return false; | ||
} | ||
|
||
return excludedParams.some((excludedParam: string) => | ||
params.some((param: string): boolean => excludedParam === param) | ||
); | ||
}; | ||
|
||
const hasExcludedUrl = ( | ||
request: Request, | ||
excludedUrls: string[] | undefined | ||
) => { | ||
return request.url && excludedUrls | ||
? excludedUrls.some((url) => request.url.search(url) > -1) | ||
: false; | ||
}; | ||
|
||
const shouldFallbackToCsr = ( | ||
request: Request, | ||
{ excludedParams, excludedUrls }: RenderingStrategyResolverOptions | ||
) => { | ||
return ( | ||
hasExcludedParams(request, excludedParams) || | ||
hasExcludedUrl(request, excludedUrls) | ||
); | ||
}; | ||
|
||
/** | ||
* Creates a rendering strategy resolver function with the specified options. | ||
* | ||
* @function | ||
* @param options - The options to configure the rendering strategy resolver. | ||
* @param [options.excludedUrls] - An optional array of URLs for which server-side rendering (SSR) should be disabled. | ||
* @param [options.excludedParams] - An optional array of Query parameters for which SSR should be disabled. | ||
* @returns A rendering strategy resolver function that takes a Request object | ||
* as a parameter and returns the rendering strategy to be applied for the request, which can be either | ||
* `RenderingStrategy.ALWAYS_CSR` or `RenderingStrategy.DEFAULT`. | ||
*/ | ||
export const defaultRenderingStrategyResolver = | ||
(options: RenderingStrategyResolverOptions) => | ||
(request: Request): RenderingStrategy => { | ||
return shouldFallbackToCsr(request, options) | ||
? RenderingStrategy.ALWAYS_CSR | ||
: RenderingStrategy.DEFAULT; | ||
}; |
This file contains 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 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
Binary file not shown.
Oops, something went wrong.