-
Notifications
You must be signed in to change notification settings - Fork 34
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
feat(headless): refresh commerce recommendations server-side #4617
base: master
Are you sure you want to change the base?
Conversation
packages/headless/src/controllers/commerce/recommendations/headless-recommendations.ssr.ts
Outdated
Show resolved
Hide resolved
Pull Request ReportPR Title✅ Title follows the conventional commit spec. Live demo linksBundle Size
SSR Progress
Detailed logssearch : buildInteractiveResultsearch : buildInteractiveInstantResult search : buildInteractiveRecentResult search : buildInteractiveCitation search : buildGeneratedAnswer recommendation : missing SSR support case-assist : missing SSR support insight : missing SSR support commerce : missing SSR support |
packages/headless/src/controllers/commerce/recommendations/headless-recommendations.ssr.ts
Outdated
Show resolved
Hide resolved
2cf64aa
to
c58b3ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nit pik.
It's quite complex tho for me to review this. @fbeaudoincoveo will probably understand it better than me.
Object.entries(controllers) | ||
.filter(([key, _]) => isRecommendationController(key)) | ||
.forEach(([_, controller]) => | ||
(controller as Recommendations).refresh?.() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We go through (some) array items twice.
Replace
array.filter(filterFn).forEach(foreachCb)
by
for (const element of array) {
if(!filterFn(element)) {
continue;
}
foreachCb(element)
}
> = TSolutionType extends SolutionType.recommendation | ||
? { | ||
/** | ||
* Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers. | ||
* | ||
* Useful for static generation and server-side rendering. | ||
*/ | ||
( | ||
controllers: Array<keyof TControllers> | ||
): Promise<EngineStaticState<TSearchAction, TControllersStaticState>>; | ||
|
||
fromBuildResult: FromBuildResult< | ||
TControllers, | ||
FetchStaticStateOptions, | ||
EngineStaticState<TSearchAction, TControllersStaticState> | ||
>; | ||
} | ||
: { | ||
/** | ||
* Executes only the initial search for a given configuration, then returns a resumable snapshot of engine state along with the state of the controllers. | ||
* | ||
* Useful for static generation and server-side rendering. | ||
*/ | ||
( | ||
...params: OptionsTuple< | ||
FetchStaticStateOptions & | ||
EngineDefinitionControllersPropsOption<TControllersProps> | ||
> | ||
): Promise<EngineStaticState<TSearchAction, TControllersStaticState>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the reason why we duplicated all of the factories to separate the types from ssr-engine. In the case of recommendation, during fetchStaticState, we are adding a controller key array prop for recommendations you want to fetch. There will never be a case where ...params
will be useful for recommendations so we removed it. It was best to create a seperate interface that can take in solutionType and do the logic in it.
const fetchRecommendationStaticState = | ||
fetchRecommendationStaticStateFactory<TControllerDefinitions>( | ||
controllerDefinitions, | ||
getOptions() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow the trail here through fetchRecommendationStaticStateFactory
to understand the filtering of the recommendation.
Adding server-side rendering for commerce SSR package only.
headless-react
package to reflect the new changesheadless-ssr-commerce
sample to reflect the new changesFeatures
Customizable Recommendation Controller
Recommendation Name Validation
Code to increase readability
Factory methods
Moved factory methods into dedicated files to avoid bloating the
commerce-engine-ssr
file.Examples include:
hydrated-state-factory.ts
static-state-factory.ts
Core Engine Types
Centralized all core engine types into
types/core-engine.ts
.Recommendation State Factories
Created dedicated factories for handling static and hydrated states for recommendations (
recommendation-static-state-factory.ts
).Improved Controller Handling
Simplified the logic for building controllers based on solution type to eliminate complex, hard-to-read conditional blocks (677fd45)
https://coveord.atlassian.net/browse/KIT-3503