feat(vtex): make hideUnavailableItems configurable at app level - #1648
Conversation
Add an app-level `hideUnavailableItems` config in vtex/mod.ts used as a default fallback across the search/shelves/listing loaders. Individual loaders can still override it via their own prop, so precedence is: loader prop > app config > false. This avoids having to set the prop page-by-page (which breaks whenever new pages are created) — new pages now inherit the store-wide default. Loaders wired to fall back to ctx.hideUnavailableItems: - intelligentSearch/productListingPage.ts (searchArgs + cacheKey) - intelligentSearch/productList.ts (fromProps + cacheKey) - legacy/relatedProductsLoader.ts (loader + cacheKey) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Tagging OptionsShould a new tag be published when this PR is merged?
|
📝 WalkthroughWalkthroughChanges
Unavailable-item filtering
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="vtex/loaders/intelligentSearch/productList.ts">
<violation number="1" location="vtex/loaders/intelligentSearch/productList.ts:160">
P2: Product-ID shelves can return a cached result with the wrong stock filtering after the app toggle changes, because their new effective `hideUnavailableItems` value is not represented in `cacheKey`. Include the resolved boolean for `isProductIDList(props)` too.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| sort: props.sort || "", | ||
| selectedFacets: [{ key: "", value: props.facets }], | ||
| hideUnavailableItems: props.hideUnavailableItems, | ||
| hideUnavailableItems: hideUnavailableItems(props), |
There was a problem hiding this comment.
P2: Product-ID shelves can return a cached result with the wrong stock filtering after the app toggle changes, because their new effective hideUnavailableItems value is not represented in cacheKey. Include the resolved boolean for isProductIDList(props) too.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At vtex/loaders/intelligentSearch/productList.ts, line 160:
<comment>Product-ID shelves can return a cached result with the wrong stock filtering after the app toggle changes, because their new effective `hideUnavailableItems` value is not represented in `cacheKey`. Include the resolved boolean for `isProductIDList(props)` too.</comment>
<file context>
@@ -147,14 +147,17 @@ const isQueryList = (p: any): p is QueryProps =>
sort: props.sort || "",
selectedFacets: [{ key: "", value: props.facets }],
- hideUnavailableItems: props.hideUnavailableItems,
+ hideUnavailableItems: hideUnavailableItems(props),
simulationBehavior: props.simulationBehavior || "default",
} as const;
</file context>
Nest the app-level default under advancedConfigs instead of top-level, keeping the VTEX config surface tidy. Loaders now read ctx.advancedConfigs?.hideUnavailableItems. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Problema
Para esconder produtos indisponíveis (out of stock) a única opção era setar a prop
hideUnavailableItemsem cada página/loader. Isso não escala: toda página nova criada volta ao comportamento padrão (false), então itens sem estoque reaparecem até alguém lembrar de setar a prop de novo.Solução
Torna
hideUnavailableItemsconfigurável no nível do app VTEX (vtex/mod.ts), usado como fallback padrão em todos os loaders relevantes. A prop por página continua funcionando e tem prioridade.Precedência:
prop do loader > config do app > falseComo
state = { ...props }no app VTEX, o valor fica disponível comoctx.hideUnavailableItems.Loaders ajustados (fallback para
ctx.hideUnavailableItems)intelligentSearch/productListingPage.ts— PLP (searchArgsOf+cacheKey)intelligentSearch/productList.ts— prateleiras/shelves (fromProps+getSearchParams/cacheKey)legacy/relatedProductsLoader.ts— produtos relacionados (loader +cacheKey)O valor do ctx foi incluído nos
cacheKeypara evitar colisão de cache quando a config muda.Como usar (ex.: Osklen)
Ligar o toggle Hide Unavailable Items na config do app VTEX. Todas as páginas — inclusive as novas — passam a esconder itens sem estoque por padrão, sem editar página por página.
Notas
loaders/legacy/productListingPage.ts), que usa a API antiga (fq) e não consome esse parâmetro.deno checklimpo nos arquivos alterados (o único erro do typecheck é pré-existente emwebsite/utils/crypto.ts, não tocado neste PR).🤖 Generated with Claude Code
Summary by cubic
Adds an app-level default to hide out-of-stock items for VTEX, now stored at
advancedConfigs.hideUnavailableItems. Search, shelves, and listings use this as a fallback to cut per-page flags and keep new pages consistent.New Features
advancedConfigs.hideUnavailableItems?: booleaninvtex/mod.ts; precedence: loader prop > app config > false.ctx.advancedConfigs?.hideUnavailableItems:intelligentSearch/productListingPage.ts,intelligentSearch/productList.ts, andlegacy/relatedProductsLoader.ts.Migration
hideUnavailableItemsprop when needed.Written for commit dd74cc5. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes