Skip to content

Conversation

@guitavano
Copy link
Contributor

@guitavano guitavano commented Nov 11, 2025

Summary by CodeRabbit

  • Refactor
    • Improved caching: merged remote suggestion results with local extra terms to produce more comprehensive search suggestions.
    • State initialization now uses the merged cached terms so suggestions are consistent on load.
    • Added safe fallbacks for missing suggestion data so search suggestions remain available and more reliable.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Warning

Rate limit exceeded

@guitavano has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dc98724 and 150ab3d.

📒 Files selected for processing (2)
  • compat/std/mod.ts (1 hunks)
  • vtex/mod.ts (4 hunks)

Walkthrough

Updated public types and runtime handling for cached search terms: added Suggestion import, changed exported App type to Awaited<ReturnType<typeof VTEX>>, changed props.cachedSearchTerms shape to an object with terms?: Suggestion and extraTerms?: string[], and introduced a local computed cachedSearchTerms merged from props.cachedSearchTerms.terms.searches and extraTerms.

Changes

Cohort / File(s) Summary
VTEX module (types & props)
vtex/mod.ts
Added Suggestion to imports; changed exported App type from ReturnType<typeof VTEX> to Awaited<ReturnType<typeof VTEX>>; updated props.cachedSearchTerms type from string[] to { terms?: Suggestion; extraTerms?: string[] }; introduced local computed cachedSearchTerms derived from props.cachedSearchTerms.terms.searches mapped to search.term plus extraTerms; initialized state cachedSearchTerms from that computed value.

Sequence Diagram

sequenceDiagram
    participant Caller as Host / Runtime
    participant VTEX as VTEX()

    Caller->>VTEX: invoke VTEX(props)
    rect rgba(248,244,230,0.7)
    note right of VTEX: compute local cachedSearchTerms (optional)
    VTEX->>VTEX: read props.cachedSearchTerms?.terms?.searches
    VTEX->>VTEX: map searches -> search.term strings
    VTEX->>VTEX: append props.cachedSearchTerms?.extraTerms
    VTEX->>VTEX: set state.cachedSearchTerms to computed array
    end
    VTEX-->>Caller: return initialized (awaited) app
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Inspect vtex/mod.ts handling of optional chaining for terms and searches.
  • Verify correct mapping from Suggestion structure to string terms and safe defaults when fields are absent.
  • Confirm the Awaited<ReturnType<...>> change aligns with consumers and exported types.

Poem

🐇 I sniffed the props and hopped around,
Collected terms where they were found,
Merged extra bits with gentle cheer,
Types awaited — the path made clear,
A cozy patch, a happy bound.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author despite the template requiring sections like contribution summary, issue link, and demonstration. Add a description following the template with: brief explanation of changes, link to relevant issue, Loom video, and demonstration link for testing.
Title check ❓ Inconclusive Title is vague and does not clearly convey the main technical change involving cachedSearchTerms refactoring and Suggestion type integration. Use a more specific title that describes the key change, e.g., 'Refactor cachedSearchTerms to support top search suggestions' or 'Add Suggestion type support to search caching'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

@github-actions
Copy link
Contributor

Tagging Options

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

  • 👍 for Patch 0.130.11 update
  • 🎉 for Minor 0.131.0 update
  • 🚀 for Major 1.0.0 update

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

🧹 Nitpick comments (1)
vtex/mod.ts (1)

171-180: Consider making the locale configurable and note initialization impact.

Two observations:

  1. The locale is hardcoded to "pt-BR" (line 175). If this app is used in other regions, consider making the locale configurable via props or deriving it from defaultSegment.

  2. This fetch blocks app initialization, adding latency to startup. This is acceptable for caching purposes, but be aware that API failures or slow responses will delay the entire app initialization.

To make locale configurable, you could add it to the Props interface:

  /**
   * @title Cached Search Terms
   * @description List of search terms that should be cached. By default, search results are not cached.
   */
  cachedSearchTerms?: string[];
+  
+  /**
+   * @title Search Terms Locale
+   * @description Locale for fetching top search terms
+   * @default pt-BR
+   */
+  searchTermsLocale?: string;

Then use it in the fetch:

    cachedSearchTerms = await vcsDeprecated
      ["GET /api/io/_v/api/intelligent-search/top_searches"]({
-        locale: "pt-BR",
+        locale: props.searchTermsLocale ?? "pt-BR",
      }).then((res) => res.json());
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a7e93d and df6f6d9.

📒 Files selected for processing (1)
  • vtex/mod.ts (3 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
vtex/mod.ts

[error] 197-197: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

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 (2)
vtex/mod.ts (2)

105-108: Breaking change: All callers must await this function.

The past review comment correctly identifies that converting VTEX to async requires updating all call sites (notably commerce/mod.ts line 39) to await the Promise.


195-198: Fix unsafe optional chaining and filter invalid search terms.

The past review comment correctly identifies the unsafe optional chaining on line 197. Additionally, there's no validation that search.term values are non-empty strings.

Apply this diff to fix both issues:

  cachedSearchTerms: [
    ...(props.cachedSearchTerms ?? []),
-    ...cachedSearchTerms?.searches?.map((search) => search.term),
+    ...(cachedSearchTerms?.searches ?? [])
+      .map((search) => search.term)
+      .filter((term): term is string => typeof term === "string" && term.length > 0),
  ],

This ensures:

  1. The spread operator receives an array (preventing TypeError)
  2. Only valid non-empty string terms are included
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df6f6d9 and 8fd95ac.

📒 Files selected for processing (1)
  • vtex/mod.ts (4 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
vtex/mod.ts

[error] 197-197: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

🔇 Additional comments (1)
vtex/mod.ts (1)

25-25: LGTM! Type correctly reflects async function.

The Awaited wrapper properly unwraps the Promise type now that VTEX is async.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fd95ac and 48f1560.

📒 Files selected for processing (1)
  • vtex/mod.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
vtex/mod.ts (2)
vtex/utils/types.ts (2)
  • Suggestion (568-570)
  • Suggestion (635-637)
commerce/types.ts (1)
  • Suggestion (867-871)
🔇 Additional comments (4)
vtex/mod.ts (4)

13-13: LGTM!

The Suggestion import is correctly added to support the new cachedSearchTerms prop structure.


182-187: LGTM!

The computed cachedSearchTerms correctly merges terms from the Suggestion object and extra terms, with proper null/undefined handling using optional chaining and nullish coalescing operators.


202-202: LGTM!

The state correctly uses the computed cachedSearchTerms array instead of the raw prop value.


95-106: The Props interface change is properly handled internally and is not breaking.

The new cachedSearchTerms object structure in the Props interface (lines 95-106) is converted to a string[] array at lines 182-187 before being placed into the state. All five loader files that consume ctx.cachedSearchTerms receive the flattened string[] format and work correctly with the .includes() method. No broken usages were found in the codebase.

Likely an incorrect or invalid review comment.

@aka-sacci-ccr aka-sacci-ccr self-assigned this Nov 12, 2025
@guitavano guitavano merged commit 2d3ef17 into main Nov 12, 2025
3 checks passed
@guitavano guitavano deleted the improve-search-cache branch November 12, 2025 15:10
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