-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(headless SSR): support both search and listing solution types (#…
…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]>
- Loading branch information
1 parent
49b33a6
commit dcd35d8
Showing
21 changed files
with
719 additions
and
185 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
Oops, something went wrong.