From 69f0caf45cdbd55db3a0e9f9c305fd0fa06cb433 Mon Sep 17 00:00:00 2001 From: Stefan Hauke Date: Tue, 30 Apr 2024 10:00:47 +0200 Subject: [PATCH] fix: remove state error when loading /recently route directly --- .../extensions/recently/store/recently/recently.reducer.ts | 2 +- .../recently/store/recently/recently.selectors.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/extensions/recently/store/recently/recently.reducer.ts b/src/app/extensions/recently/store/recently/recently.reducer.ts index b28d4983ea..82a4d06f37 100644 --- a/src/app/extensions/recently/store/recently/recently.reducer.ts +++ b/src/app/extensions/recently/store/recently/recently.reducer.ts @@ -6,7 +6,7 @@ import { addToRecently, clearRecently } from './recently.actions'; export type RecentlyViewedProducts = RecentlyViewedProduct[]; -const initialState: RecentlyViewedProducts = []; +export const initialState: RecentlyViewedProducts = []; export const recentlyReducer = createReducer( [], diff --git a/src/app/extensions/recently/store/recently/recently.selectors.ts b/src/app/extensions/recently/store/recently/recently.selectors.ts index 54c0028135..ae54cb8171 100644 --- a/src/app/extensions/recently/store/recently/recently.selectors.ts +++ b/src/app/extensions/recently/store/recently/recently.selectors.ts @@ -5,9 +5,9 @@ import { isArrayEqual } from 'ish-core/utils/functions'; import { getRecentlyState } from '../recently-store'; -import { RecentlyViewedProducts } from './recently.reducer'; +import { RecentlyViewedProducts, initialState } from './recently.reducer'; -const internalProducts = createSelector(getRecentlyState, state => state._recently); +const internalProducts = createSelector(getRecentlyState, state => state?._recently || initialState); export const getRecentlyViewedProducts = createSelectorFactory(projector => resultMemoize(projector, isArrayEqual) @@ -21,7 +21,7 @@ export const getRecentlyViewedProducts = createSelectorFactory ); /** - * Selector to get the most recent 4 products without the currently viewed product on product detail pages + * Selector to get the most recent 12 products without the currently viewed product on product detail pages */ export const getMostRecentlyViewedProducts = createSelector( getRecentlyViewedProducts,