-
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 SSR): support both search and listing solution types #4249
Merged
Conversation
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
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Aug 19, 2024
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 15:41
— with
GitHub Actions
Inactive
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 16:06
— with
GitHub Actions
Inactive
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 19:21
— with
GitHub Actions
Inactive
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 19:50
— with
GitHub Actions
Inactive
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Aug 19, 2024
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 20:14
— with
GitHub Actions
Inactive
alexprudhomme
temporarily deployed
to
PR Artifacts
August 19, 2024 20:42
— with
GitHub Actions
Inactive
fpbrault
pushed a commit
that referenced
this pull request
Aug 23, 2024
…4249) ## TL;DR Enhance the commerce engine to support both search and listing solution types, implementing type inference and conditional types to ensure the correct controllers are instantiated based on the solution type. ## Key Changes ### **Solution Type Support**: The commerce engine now supports both search and listing solution types. This is particularly important when building sub-controllers (e.g., summary, facets, sort, etc.). Since, in SSR, users do not manually build their controllers because it is done under the hood (in the SSR utils), the SSR utils need to know which function to call (e.g., `buildProductListing()` or `buildSearch()`). ### **Conditional Controller Instantiation**: Based on the specified solution type, the engine now conditionally instantiates controllers. This mechanism ensures that only relevant controllers are active for a given solution type, optimizing the engine’s performance and resource usage by avoiding the creation of unnecessary controllers. #### Example For instance, if you create an engine definition containing a Query Summary but want the QuerySummary controller to not be created on listing pages, you can opt out for this solution type. Otherwise, it will be built like other controllers. ```ts const engineDefinition = defineCommerceEngine({ configuration: configuration, controllers: { searchbox: defineStandaloneSearchBox({ options: {redirectionUrl: '/search'}, }), summary: defineQuerySummary({listing: false}), // opting out for listing context // ... other controllers }, }); ``` ### **Type Inference Enhancements**: Since Conditional Controller Instantiation is a runtime logic, I had to update the typing to reflect that change so that the same logic could also be available statically with TypeScript. This means that if you opt out from a solution type during the engine definition (like in the previous example), you should not have the controller available when using code completion. These enhancements facilitate the accurate determination of controller types based on the solution type, streamlining the setup process for developers. #### Example Using the same engine definition from the previous example, and since we have opted out from query summary in the listing context, you will notice that you get an error if you try to get that controller in the listing context. ![image](https://github.com/user-attachments/assets/6724fd40-4a37-4a0f-9b20-15a9d93e1a3b) ### **Duplicate Types and Methods**: Due to compatibility issues with existing types used by the non-commerce SSR package, some types and methods have been duplicated and adapted to fit the solution type strategy. https://coveord.atlassian.net/browse/KIT-3394 --------- Co-authored-by: Alex Prudhomme <[email protected]> Co-authored-by: Frederic Beaudoin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR
Enhance the commerce engine to support both search and listing solution types, implementing type inference and conditional types to ensure the correct controllers are instantiated based on the solution type.
Key Changes
Solution Type Support:
The commerce engine now supports both search and listing solution types. This is particularly important when building sub-controllers (e.g., summary, facets, sort, etc.). Since, in SSR, users do not manually build their controllers because it is done under the hood (in the SSR utils), the SSR utils need to know which function to call (e.g.,
buildProductListing()
orbuildSearch()
).Conditional Controller Instantiation:
Based on the specified solution type, the engine now conditionally instantiates controllers. This mechanism ensures that only relevant controllers are active for a given solution type, optimizing the engine’s performance and resource usage by avoiding the creation of unnecessary controllers.
Example
For instance, if you create an engine definition containing a Query Summary but want the QuerySummary controller to not be created on listing pages, you can opt out for this solution type. Otherwise, it will be built like other controllers.
Type Inference Enhancements:
Since Conditional Controller Instantiation is a runtime logic, I had to update the typing to reflect that change so that the same logic could also be available statically with TypeScript. This means that if you opt out from a solution type during the engine definition (like in the previous example), you should not have the controller available when using code completion.
These enhancements facilitate the accurate determination of controller types based on the solution type, streamlining the setup process for developers.
Example
Using the same engine definition from the previous example, and since we have opted out from query summary in the listing context, you will notice that you get an error if you try to get that controller in the listing context.
Duplicate Types and Methods:
Due to compatibility issues with existing types used by the non-commerce SSR package, some types and methods have been duplicated and adapted to fit the solution type strategy.
https://coveord.atlassian.net/browse/KIT-3394