Skip to content

Conversation

@guitavano
Copy link
Contributor

@guitavano guitavano commented Nov 14, 2025

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved search caching to handle queries case-insensitively, ensuring consistent behavior and performance whether searches use uppercase, lowercase, or mixed-case search terms.

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.133.2 update
  • 🎉 for Minor 0.134.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

The pull request applies case-insensitive search term handling across product loader cache mechanisms. Search terms are lowercased before cache membership checks in five loader files spanning both intelligentSearch and legacy modules, ensuring cache hits regardless of query term casing.

Changes

Cohort / File(s) Summary
IntelligentSearch product loaders
vtex/loaders/intelligentSearch/productList.ts, vtex/loaders/intelligentSearch/productListingPage.ts
Search term cache lookups now lowercase the term before checking against cachedSearchTerms for case-insensitive cache eligibility
Legacy product loaders
vtex/loaders/legacy/productList.ts, vtex/loaders/legacy/productListingPage.ts, vtex/loaders/legacy/relatedProductsLoader.ts
Search term cache membership checks now use lowercased search terms to enable case-insensitive cache lookups

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Notes for review:

  • Highly repetitive and homogeneous changes across all five files simplify verification
  • Confirm consistent application of toLowerCase() in all cache key comparisons
  • Verify no edge cases exist where case sensitivity was intentionally preserved

Possibly related PRs

  • deco-cx/apps#1447: Modifies cacheKey logic in productListingPage.ts with additional URL parameter filtering
  • deco-cx/apps#1459: Introduces ctx.cachedSearchTerms gating for the same loader cacheKey logic across intelligentSearch and legacy modules

Suggested reviewers

  • viktormarinho

Poem

🐰 A search that dances,
Case matters no more,
Lowercase whispers find
The cache forevermore,
Swift hops through data—
Consistency restored!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely missing; no description content was provided by the author. Add a pull request description following the template with sections: 'What is this Contribution About?', 'Issue Link', 'Loom Video', and 'Demonstration Link'.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change across all modified files: making search term comparisons case-insensitive by converting to lowercase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tavano-to-lower-case

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (4)
vtex/loaders/intelligentSearch/productListingPage.ts (1)

437-437: LGTM: Consistent case-insensitive cache lookup.

This change aligns with the same pattern applied across all loader files in this PR, enabling case-insensitive search term caching.

vtex/loaders/legacy/productList.ts (1)

294-294: LGTM: Consistent case-insensitive cache lookup.

This change aligns with the same pattern applied across all loader files in this PR. The ctx.isInvoke check remains appropriately unchanged.

vtex/loaders/legacy/productListingPage.ts (1)

449-449: LGTM: Consistent case-insensitive cache lookup.

This change aligns with the same pattern applied across all loader files in this PR, enabling case-insensitive search term caching.

vtex/loaders/intelligentSearch/productList.ts (1)

321-321: LGTM: Consistent case-insensitive cache lookup.

This change aligns with the same pattern applied across all loader files in this PR. The ctx.isInvoke check remains appropriately unchanged.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bce273d and 26baa35.

📒 Files selected for processing (5)
  • vtex/loaders/intelligentSearch/productList.ts (1 hunks)
  • vtex/loaders/intelligentSearch/productListingPage.ts (1 hunks)
  • vtex/loaders/legacy/productList.ts (1 hunks)
  • vtex/loaders/legacy/productListingPage.ts (1 hunks)
  • vtex/loaders/legacy/relatedProductsLoader.ts (1 hunks)

const searchTerm = url.searchParams.get("ft") || url.searchParams.get("q");
const cachedSearchTerms = ctx.cachedSearchTerms ?? [];
if (searchTerm && !cachedSearchTerms.includes(searchTerm)) {
if (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that cachedSearchTerms contains lowercase values.

The change correctly lowercases the searchTerm before checking inclusion in cachedSearchTerms. However, for this to work as intended, the cachedSearchTerms array must also contain only lowercase values. If cachedSearchTerms contains mixed-case terms (e.g., "Shoes"), this change could cause cache misses when the user searches for "shoes".

Run the following script to verify how cachedSearchTerms is populated and whether values are normalized to lowercase:


🏁 Script executed:

#!/bin/bash
# Search for where cachedSearchTerms is assigned or populated
rg -nP '\bcachedSearchTerms\s*[:=]' -A 3 -B 1

# Search for where ctx.cachedSearchTerms is set
rg -nP 'ctx\.cachedSearchTerms\s*=' -A 3 -B 1

# Look for any toLowerCase() normalization when populating cachedSearchTerms
rg -nP 'cachedSearchTerms.*toLowerCase|toLowerCase.*cachedSearchTerms' -C 2

Length of output: 5201


Fix case-sensitivity mismatch in searchTerm comparison across all loaders.

The verification confirms your concern is valid. cachedSearchTerms is populated in vtex/mod.ts:183-186 without lowercasing (search.term), but multiple loaders lowercase the searchTerm during comparison (searchTerm.toLowerCase()). This causes cache misses when cached terms contain uppercase letters.

This pattern exists in:

  • vtex/loaders/legacy/relatedProductsLoader.ts:164
  • vtex/loaders/legacy/productListingPage.ts:449
  • vtex/loaders/legacy/productList.ts:294
  • vtex/loaders/intelligentSearch/productListingPage.ts:437
  • vtex/loaders/intelligentSearch/productList.ts:321

Normalize cachedSearchTerms to lowercase in vtex/mod.ts during population, or remove the .toLowerCase() call from all comparison checks to ensure consistency.

🤖 Prompt for AI Agents
In vtex/loaders/legacy/relatedProductsLoader.ts around line 164 the comparison
uses searchTerm.toLowerCase() against cachedSearchTerms which are populated
without lowercasing in vtex/mod.ts (lines ~183-186), causing cache misses; fix
by normalizing cachedSearchTerms to lowercase when you populate them in
vtex/mod.ts (i.e., push search.term.toLowerCase()), or alternatively remove the
.toLowerCase() from comparisons in all affected loaders
(vtex/loaders/legacy/relatedProductsLoader.ts:164,
vtex/loaders/legacy/productListingPage.ts:449,
vtex/loaders/legacy/productList.ts:294,
vtex/loaders/intelligentSearch/productListingPage.ts:437,
vtex/loaders/intelligentSearch/productList.ts:321) so both sides are consistent.

@guitavano guitavano merged commit 62f8dac into main Nov 14, 2025
7 checks passed
@guitavano guitavano deleted the tavano-to-lower-case branch November 14, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants