+
diff --git a/packages/samples/headless-commerce-react/src/index.css b/packages/samples/headless-commerce-react/src/index.css
index 7323ae85c54..afd0f7965af 100644
--- a/packages/samples/headless-commerce-react/src/index.css
+++ b/packages/samples/headless-commerce-react/src/index.css
@@ -1,5 +1,5 @@
body {
- margin: 0;
+ margin: 1rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
diff --git a/packages/samples/headless-commerce-react/src/layout/layout.tsx b/packages/samples/headless-commerce-react/src/layout/layout.tsx
index cb900bfe3ed..3410fa9cfd1 100644
--- a/packages/samples/headless-commerce-react/src/layout/layout.tsx
+++ b/packages/samples/headless-commerce-react/src/layout/layout.tsx
@@ -1,5 +1,6 @@
import {
buildCart,
+ buildInstantProducts,
buildStandaloneSearchBox,
CommerceEngine,
} from '@coveo/headless/commerce';
@@ -17,6 +18,8 @@ interface ILayoutProps {
export default function Layout(props: ILayoutProps) {
const {engine, isPending, navigate, children} = props;
+ const standaloneSearchBoxId = 'standalone-search-box';
+
return (
@@ -93,10 +96,13 @@ export default function Layout(props: ILayoutProps) {
controller={buildStandaloneSearchBox(engine, {
options: {
redirectionUrl: '/search',
- id: 'standalone-search-box',
+ id: standaloneSearchBoxId,
highlightOptions,
},
})}
+ instantProductsController={buildInstantProducts(engine, {
+ options: {searchBoxId: standaloneSearchBoxId},
+ })}
/>
)}
diff --git a/packages/samples/headless-commerce-react/src/pages/cart-page.tsx b/packages/samples/headless-commerce-react/src/pages/cart-page.tsx
index 50cea6edac9..16d4898f6c0 100644
--- a/packages/samples/headless-commerce-react/src/pages/cart-page.tsx
+++ b/packages/samples/headless-commerce-react/src/pages/cart-page.tsx
@@ -24,6 +24,10 @@ export default function CartPage(props: ICartPageProps) {
});
useEffect(() => {
+ /**
+ * It is important to call the `Context` controller's `setView` method with the current URL when a page is loaded,
+ * as the Commerce API requires this information to function properly.
+ */
contextController.setView({url});
if (
diff --git a/packages/samples/headless-commerce-react/src/pages/home-page.tsx b/packages/samples/headless-commerce-react/src/pages/home-page.tsx
index 9c34fde235d..4c445dbb5cc 100644
--- a/packages/samples/headless-commerce-react/src/pages/home-page.tsx
+++ b/packages/samples/headless-commerce-react/src/pages/home-page.tsx
@@ -23,6 +23,10 @@ export default function HomePage(props: IHomePageProps) {
});
useEffect(() => {
+ /**
+ * It is important to call the `Context` controller's `setView` method with the current URL when a page is loaded,
+ * as the Commerce API requires this information to function properly.
+ */
contextController.setView({url});
if (
diff --git a/packages/samples/headless-commerce-react/src/pages/product-description-page.tsx b/packages/samples/headless-commerce-react/src/pages/product-description-page.tsx
index c290c6c79de..d6413fd2513 100644
--- a/packages/samples/headless-commerce-react/src/pages/product-description-page.tsx
+++ b/packages/samples/headless-commerce-react/src/pages/product-description-page.tsx
@@ -46,6 +46,10 @@ export default function ProductDescriptionPage(
const product = loadProduct();
useEffect(() => {
+ /**
+ * It is important to call the `Context` controller's `setView` method with the current URL when a page is loaded,
+ * as the Commerce API requires this information to function properly.
+ */
contextController.setView({url});
}, [contextController, url]);
diff --git a/packages/samples/headless-commerce-react/src/pages/product-listing-page.tsx b/packages/samples/headless-commerce-react/src/pages/product-listing-page.tsx
index a827542a63b..720a374412a 100644
--- a/packages/samples/headless-commerce-react/src/pages/product-listing-page.tsx
+++ b/packages/samples/headless-commerce-react/src/pages/product-listing-page.tsx
@@ -52,6 +52,16 @@ export default function ProductListingPage(props: IProductListingPageProps) {
}, [productListingController]);
useEffect(() => {
+ /**
+ * It is important to call the `Context` controller's `setView` method with the current URL when a page is loaded,
+ * as the Commerce API requires this information to function properly.
+ *
+ * Note, however, that calling this method will reset the query, pagination, sort, and facets.
+ *
+ * This means that on a search or listing page, you must call this method BEFORE you bind the URL manager.
+ * Otherwise, the URL manager will restore the state from the URL parameters, and then this state will get
+ * immediately reset when the `setView` method is called.
+ */
contextController.setView({url});
const unsubscribe = bindUrlManager();
diff --git a/packages/samples/headless-commerce-react/src/pages/search-page.tsx b/packages/samples/headless-commerce-react/src/pages/search-page.tsx
index b188b8faaff..58e76f09665 100644
--- a/packages/samples/headless-commerce-react/src/pages/search-page.tsx
+++ b/packages/samples/headless-commerce-react/src/pages/search-page.tsx
@@ -1,4 +1,5 @@
import {
+ buildInstantProducts,
buildSearch,
buildSearchBox,
Cart,
@@ -25,8 +26,10 @@ export default function Search(props: ISearchProps) {
contextController.setView({url});
const searchController = buildSearch(engine);
+
+ const searchBoxId = 'search-box';
const searchBoxController = buildSearchBox(engine, {
- options: {id: 'search-box', highlightOptions},
+ options: {id: searchBoxId, highlightOptions},
});
const bindUrlManager = useCallback(() => {
@@ -58,6 +61,16 @@ export default function Search(props: ISearchProps) {
}, [searchController]);
useEffect(() => {
+ /**
+ * It is important to call the `Context` controller's `setView` method with the current URL when a page is loaded,
+ * as the Commerce API requires this information to function properly.
+ *
+ * Note, however, that calling this method will reset the query, pagination, sort, and facets.
+ *
+ * This means that on a search or listing page, you must call this method BEFORE you bind the URL manager.
+ * Otherwise, the URL manager will restore the state from the URL parameters, and then this state will get
+ * immediately reset when the `setView` method is called.
+ */
contextController.setView({url});
const unsubscribe = bindUrlManager();
@@ -84,7 +97,13 @@ export default function Search(props: ISearchProps) {
return (
-
+
Search