Skip to content

exclude map from cacheKey#1570

Merged
guitavano merged 2 commits intomainfrom
tavano/exclude-map
Apr 9, 2026
Merged

exclude map from cacheKey#1570
guitavano merged 2 commits intomainfrom
tavano/exclude-map

Conversation

@guitavano
Copy link
Copy Markdown
Contributor

@guitavano guitavano commented Apr 9, 2026

What is this Contribution About?

Please provide a brief description of the changes or enhancements you are proposing in this pull request.

Issue Link

Please link to the relevant issue that this pull request addresses:

Loom Video

Record a quick screencast describing your changes to help the team understand and review your contribution. This will greatly assist in the review process.

Demonstration Link

Provide a link to a branch or environment where this pull request can be tested and seen in action.


Summary by cubic

Skip caching for product listing pages when the URL contains map= to avoid stale faceted results. cacheKey still returns null for new search terms not in ctx.cachedSearchTerms.

Written for commit 07ed5b2. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved product listing page cache logic to detect specific URL query parameters and bypass caching when appropriate, preventing incorrect cached results and ensuring users see accurate listings for those requests.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Tagging Options

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

  • 👍 for Patch 0.144.2 update
  • 🎉 for Minor 0.145.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96be99d8-2954-48e4-a820-bcf46d7348b6

📥 Commits

Reviewing files that changed from the base of the PR and between 88e8720 and 07ed5b2.

📒 Files selected for processing (1)
  • vtex/loaders/legacy/productListingPage.ts
✅ Files skipped from review due to trivial changes (1)
  • vtex/loaders/legacy/productListingPage.ts

📝 Walkthrough

Walkthrough

Updated the cacheKey function in the legacy product listing page loader to return null whenever the request URL contains a map= query parameter, expanding the existing cache-prevention checks tied to search-term handling.

Changes

Cohort / File(s) Summary
Caching Logic
vtex/loaders/legacy/productListingPage.ts
Added a hasMap check to cacheKey and early-return null when map= is present in the request URL; preserved existing cache-key construction otherwise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • viktormarinho

Poem

🐰 I sniffed the URL, then took a nap,
A tiny map= made me ditch the cache cap.
Hopping through queries, so spry and spry,
I leave no stale keys as I bound by. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'exclude map from cacheKey' directly and accurately summarizes the main change: adding a check to exclude URLs with 'map=' from the caching mechanism.
Description check ✅ Passed The PR description uses the required template structure but has unfilled placeholder sections (Issue Link, Loom Video, Demonstration Link). However, the auto-generated cubic summary provides substantive context about the caching behavior change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tavano/exclude-map

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
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@vtex/loaders/legacy/productListingPage.ts`:
- Around line 454-457: The conditional starting at the if using hasMap,
searchTerm, and cachedSearchTerms is misformatted; run the Deno formatter (deno
fmt) and commit the result so the block around the if (hasMap || (searchTerm &&
!cachedSearchTerms.includes(searchTerm.toLowerCase()))) { ... } and the
following declaration of fq are properly formatted according to project style.
- Around line 452-454: The code uses substring matching to set hasMap (const
hasMap = url.search.includes("map=")), which can falsely detect map when it
appears inside other params and cause cacheKey to be null; change detection to
be key-aware by using the URLSearchParams API (use url.searchParams.has('map'))
so hasMap accurately reflects the presence of the map param; update the
conditional that uses hasMap (the if using hasMap || (searchTerm &&
!cachedSearchTerms.includes(...))) and keep existing references to
ctx.cachedSearchTerms, cachedSearchTerms, and searchTerm unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ccc9daec-f7c0-4b2c-bcc4-022c2b05dc5d

📥 Commits

Reviewing files that changed from the base of the PR and between 5954499 and 88e8720.

📒 Files selected for processing (1)
  • vtex/loaders/legacy/productListingPage.ts

Comment on lines +452 to +454
const hasMap = url.search.includes("map=");
const cachedSearchTerms = ctx.cachedSearchTerms ?? [];
if (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase())) {
if (hasMap || (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase()))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the map-detection implementation in cacheKey and check for raw substring usage.
rg -n -C2 'const hasMap\s*=' vtex/loaders/legacy/productListingPage.ts
rg -n -C2 'search\.includes\("map="\)|searchParams\.has\("map"\)' vtex/loaders/legacy/productListingPage.ts

Repository: deco-cx/apps

Length of output: 637


🏁 Script executed:

#!/bin/bash
# Check the broader context: how is 'url' created/typed, and confirm searchParams availability
# Also check if there are other uses of the map parameter to understand the feature context

# Get more context around line 452 to see url object creation
sed -n '440,460p' vtex/loaders/legacy/productListingPage.ts

# Search for how 'url' is defined in this function
rg -n 'function|const url|let url|url\s*=' vtex/loaders/legacy/productListingPage.ts | head -20

# Check if url.searchParams is used elsewhere in the file
rg -n 'url\.searchParams' vtex/loaders/legacy/productListingPage.ts

# Look for any map parameter usage context
rg -n 'map' vtex/loaders/legacy/productListingPage.ts | head -30

Repository: deco-cx/apps

Length of output: 3154


🏁 Script executed:

#!/bin/bash
# Check TypeScript context and any type constraints
head -30 vtex/loaders/legacy/productListingPage.ts | grep -E "import|export|interface|type"

# Check if the cacheKey function has explicit type annotations
sed -n '449,455p' vtex/loaders/legacy/productListingPage.ts

Repository: deco-cx/apps

Length of output: 926


Use exact map key detection to avoid unintended cache bypass.

Line 452 uses raw substring matching (url.search.includes("map=")), which can incorrectly match map= within other parameter values or names (e.g., utm_campaign=email_map=test), causing cacheKey to return null unexpectedly and bypass caching.

The codebase already uses url.searchParams throughout the file, so the proper solution is to use key-aware detection:

Proposed fix
-  const hasMap = url.search.includes("map=");
+  const hasMap = url.searchParams.has("map");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const hasMap = url.search.includes("map=");
const cachedSearchTerms = ctx.cachedSearchTerms ?? [];
if (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase())) {
if (hasMap || (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase()))) {
const hasMap = url.searchParams.has("map");
const cachedSearchTerms = ctx.cachedSearchTerms ?? [];
if (hasMap || (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase()))) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vtex/loaders/legacy/productListingPage.ts` around lines 452 - 454, The code
uses substring matching to set hasMap (const hasMap =
url.search.includes("map=")), which can falsely detect map when it appears
inside other params and cause cacheKey to be null; change detection to be
key-aware by using the URLSearchParams API (use url.searchParams.has('map')) so
hasMap accurately reflects the presence of the map param; update the conditional
that uses hasMap (the if using hasMap || (searchTerm &&
!cachedSearchTerms.includes(...))) and keep existing references to
ctx.cachedSearchTerms, cachedSearchTerms, and searchTerm unchanged.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

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/legacy/productListingPage.ts">

<violation number="1" location="vtex/loaders/legacy/productListingPage.ts:452">
P2: Use searchParams.has("map") instead of a substring match so only the actual `map` query parameter disables caching.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

const url = new URL(props.pageHref || req.url);

const searchTerm = url.searchParams.get("ft") || url.searchParams.get("q");
const hasMap = url.search.includes("map=");
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

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

P2: Use searchParams.has("map") instead of a substring match so only the actual map query parameter disables caching.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At vtex/loaders/legacy/productListingPage.ts, line 452:

<comment>Use searchParams.has("map") instead of a substring match so only the actual `map` query parameter disables caching.</comment>

<file context>
@@ -449,8 +449,9 @@ export const cacheKey = (props: Props, req: Request, ctx: AppContext) => {
   const url = new URL(props.pageHref || req.url);
 
   const searchTerm = url.searchParams.get("ft") || url.searchParams.get("q");
+  const hasMap = url.search.includes("map=");
   const cachedSearchTerms = ctx.cachedSearchTerms ?? [];
-  if (searchTerm && !cachedSearchTerms.includes(searchTerm.toLowerCase())) {
</file context>
Suggested change
const hasMap = url.search.includes("map=");
const hasMap = url.searchParams.has("map");
Fix with Cubic

@guitavano guitavano merged commit cc09f52 into main Apr 9, 2026
5 checks passed
@guitavano guitavano deleted the tavano/exclude-map branch April 9, 2026 11:09
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.

1 participant