Skip to content

Conversation

@jezzzm
Copy link

@jezzzm jezzzm commented Oct 29, 2025

Pull Request

Related issue

Fixes #1417

What does this PR do?

  • defends against missing value key in some attributes for highlighting
  • specifically: non-primitive values (or arrays of non-primitives) may not include value as a key

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • Refactor
    • Improved handling of search result highlighting with enhanced type safety and runtime validation to ensure more reliable highlight processing across search results.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

⚠️ No Changeset found

Latest commit: 5b9235f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Warning

Rate limit exceeded

@jezzzm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 51 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 215601a and 5b9235f.

📒 Files selected for processing (3)
  • packages/autocomplete-client/__tests__/test.utils.ts (6 hunks)
  • packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts (1 hunks)
  • packages/autocomplete-client/src/search/fetchMeilisearchResults.ts (2 hunks)

Walkthrough

Adds defensive runtime guards and union types to handle potentially undefined highlight result values from Meilisearch, preventing type errors when non-primitive fields lack required value properties.

Changes

Cohort / File(s) Change Summary
Highlight Result Type Safety
packages/autocomplete-client/src/search/fetchMeilisearchResults.ts
Introduces union type PossibleHighlightResult with new helper types DefinedHighlightResult and UndefinedHighlightResult; adds isDefinedHighlightValue runtime guard to detect defined highlight values; refactors reduce logic to conditionally mutate accumulator only when highlight value is defined; integrates mapOneOrMany and calculateHighlightMetadata for flexible highlight result handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Type system changes: Review new union types and discriminator function to ensure correctness and proper coverage of edge cases
  • Reduce logic refactoring: Verify mutation pattern in accumulator correctly handles both defined and undefined highlight values
  • Integration points: Confirm mapOneOrMany and calculateHighlightMetadata are applied appropriately to single and array highlight results

Poem

🐰 Hopping through highlights with care,
We guard against values that aren't there,
Type-safe and clever, the logic is keen,
Defending each field from the Meilisearch scene!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix(autocomplete): gracefully handle missing values when parsing highlights" directly aligns with the main change described in the raw summary. The title clearly identifies that this is a fix for the autocomplete feature that addresses the graceful handling of missing values during highlight parsing. The title is concise, uses conventional commit format, and provides specific information about what is being fixed without unnecessary verbosity or vague terminology.
Linked Issues Check ✅ Passed The code changes directly address the primary objective from issue #1417, which is to make the autocomplete frontend parsing defensive so it does not throw type errors when a value key is absent for an attribute highlight result. The changes introduce a runtime guard isDefinedHighlightValue to detect defined highlight values and skip fields that lack valid values, which implements the defensive handling needed. The PR appropriately focuses on the frontend parsing layer rather than the server-side filtering, which is acknowledged as a larger separate change.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly related to the objective of defensively handling missing value keys in highlight results. The modifications include introducing union types for highlight results, adding a runtime guard function, refactoring the reduce logic, and applying highlight metadata calculations—all of which support the core goal of preventing type errors when parsing highlights with missing values. No unrelated changes such as formatting, refactoring of unrelated code, or additional features are present.

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

@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 043669a and 215601a.

📒 Files selected for processing (1)
  • packages/autocomplete-client/src/search/fetchMeilisearchResults.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/autocomplete-client/src/search/fetchMeilisearchResults.ts (1)
packages/autocomplete-client/src/constants/index.ts (2)
  • HIGHLIGHT_PRE_TAG (1-1)
  • HIGHLIGHT_POST_TAG (2-2)
🔇 Additional comments (3)
packages/autocomplete-client/src/search/fetchMeilisearchResults.ts (3)

153-164: LGTM: Type definitions correctly model the problem.

The union type structure cleanly handles both scalar and array highlight results that may or may not have a value property. The comment usefully documents the server behavior this is working around.


67-88: LGTM: Defensive handling and clean refactoring.

The early return on lines 70-72 gracefully skips highlight results without defined values, preventing type errors. The refactored logic using mapOneOrMany and direct mutation of the accumulator is both clearer and more efficient than creating intermediate objects.

Line 82's access to highlightResult.value is safe because isDefinedHighlightValue has confirmed its presence.


148-151: LGTM: Clean, reusable helper.

The mapOneOrMany abstraction correctly handles both scalar and array values with appropriate type inference.

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.

autocomplete highlighting type errors when handling fields with non-primitive values

1 participant