Skip to content

Commit a1e2bff

Browse files
committed
Fixes #4794: Fix marketplace blanking after populating
- Fixed state management issue in MarketplaceViewStateManager where displayItems was not properly initialized - Improved handling of marketplace items when no filters are active to ensure all items are displayed - Enhanced initial state loading logic to prevent infinite loops and ensure proper state updates - Fixed getState method to fall back to allItems when displayItems is empty The issue was caused by displayItems being set to an empty array when marketplace items were loaded, even when no filters were applied. This caused the marketplace to appear blank after loading completed.
1 parent 2e2f83b commit a1e2bff

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

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

4747
// Listen for state changes to know when initial data arrives
4848
const unsubscribe = manager.onStateChange((newState) => {
49-
if (newState.allItems.length > 0 && !hasReceivedInitialState) {
49+
// Mark as received initial state when we get any state update
50+
// This prevents infinite loops and ensures proper state handling
51+
if (!hasReceivedInitialState && (newState.allItems.length > 0 || newState.displayItems !== undefined)) {
5052
setHasReceivedInitialState(true)
5153
}
5254
})

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
@@ -170,11 +171,20 @@ export class MarketplaceViewStateManager {
170171
break
171172
}
172173

174+
// Calculate display items based on current filters
175+
let newDisplayItems: MarketplaceItem[]
176+
if (this.isFilterActive()) {
177+
newDisplayItems = this.filterItems([...items])
178+
} else {
179+
// No filters active - show all items
180+
newDisplayItems = [...items]
181+
}
182+
173183
// Update allItems as source of truth
174184
this.state = {
175185
...this.state,
176186
allItems: [...items],
177-
displayItems: this.isFilterActive() ? this.filterItems([...items]) : [...items],
187+
displayItems: newDisplayItems,
178188
isFetching: false,
179189
}
180190

@@ -309,7 +319,17 @@ export class MarketplaceViewStateManager {
309319
// Always use the marketplace items from the extension when they're provided
310320
// This ensures fresh data is always displayed
311321
const items = [...marketplaceItems]
312-
const newDisplayItems = this.isFilterActive() ? this.filterItems(items) : items
322+
323+
// Calculate display items based on current filters
324+
// If no filters are active, show all items
325+
// If filters are active, apply filtering
326+
let newDisplayItems: MarketplaceItem[]
327+
if (this.isFilterActive()) {
328+
newDisplayItems = this.filterItems(items)
329+
} else {
330+
// No filters active - show all items
331+
newDisplayItems = items
332+
}
313333

314334
// Update state in a single operation
315335
this.state = {

0 commit comments

Comments
 (0)