Skip to content

Commit d598fc3

Browse files
roomotedaniel-lxs
andauthored
Fixes #4794: Fix marketplace blanking after populating (#4796)
Co-authored-by: Daniel Riccio <[email protected]>
1 parent 7a8483d commit d598fc3

File tree

3 files changed

+423
-4
lines changed

3 files changed

+423
-4
lines changed

webview-ui/src/components/marketplace/MarketplaceView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export function MarketplaceView({ stateManager, onDone }: MarketplaceViewProps)
4242

4343
// Listen for state changes to know when initial data arrives
4444
const unsubscribe = manager.onStateChange((newState) => {
45-
if (newState.allItems.length > 0 && !hasReceivedInitialState) {
45+
// Mark as received initial state when we get any state update
46+
// This prevents infinite loops and ensures proper state handling
47+
if (!hasReceivedInitialState && (newState.allItems.length > 0 || newState.displayItems !== undefined)) {
4648
setHasReceivedInitialState(true)
4749
}
4850
})

webview-ui/src/components/marketplace/MarketplaceViewStateManager.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export class MarketplaceViewStateManager {
9797
// Only create new arrays if they exist and have items
9898
const allItems = this.state.allItems.length ? [...this.state.allItems] : []
9999
// Ensure displayItems is always an array, never undefined
100-
const displayItems = this.state.displayItems ? [...this.state.displayItems] : []
100+
// If displayItems is undefined or null, fall back to allItems
101+
const displayItems = this.state.displayItems ? [...this.state.displayItems] : [...allItems]
101102
const tags = this.state.filters.tags.length ? [...this.state.filters.tags] : []
102103

103104
// Create minimal new state object
@@ -174,11 +175,20 @@ export class MarketplaceViewStateManager {
174175
break
175176
}
176177

178+
// Calculate display items based on current filters
179+
let newDisplayItems: MarketplaceItem[]
180+
if (this.isFilterActive()) {
181+
newDisplayItems = this.filterItems([...items])
182+
} else {
183+
// No filters active - show all items
184+
newDisplayItems = [...items]
185+
}
186+
177187
// Update allItems as source of truth
178188
this.state = {
179189
...this.state,
180190
allItems: [...items],
181-
displayItems: this.isFilterActive() ? this.filterItems([...items]) : [...items],
191+
displayItems: newDisplayItems,
182192
isFetching: false,
183193
}
184194

@@ -322,7 +332,17 @@ export class MarketplaceViewStateManager {
322332
// Always use the marketplace items from the extension when they're provided
323333
// This ensures fresh data is always displayed
324334
const items = [...marketplaceItems]
325-
const newDisplayItems = this.isFilterActive() ? this.filterItems(items) : items
335+
336+
// Calculate display items based on current filters
337+
// If no filters are active, show all items
338+
// If filters are active, apply filtering
339+
let newDisplayItems: MarketplaceItem[]
340+
if (this.isFilterActive()) {
341+
newDisplayItems = this.filterItems(items)
342+
} else {
343+
// No filters active - show all items
344+
newDisplayItems = items
345+
}
326346

327347
// Update state in a single operation
328348
this.state = {

0 commit comments

Comments
 (0)