Skip to content

fix: suggestions object key with constructor#2586

Merged
SoonIter merged 2 commits intomainfrom
fix/normalize-suggestion-with-keywords
Sep 11, 2025
Merged

fix: suggestions object key with constructor#2586
SoonIter merged 2 commits intomainfrom
fix/normalize-suggestion-with-keywords

Conversation

@zoolsher
Copy link
Member

@zoolsher zoolsher commented Sep 11, 2025

Summary

This pull request refactors the way search suggestions are grouped and accessed in the SearchPanel component. The main change is switching from using a plain JavaScript object to a Map for grouping suggestions, which improves code clarity and consistency when handling dynamic keys.

Refactor of suggestions grouping and iteration:

  • Changed the normalizeSuggestions function to return a Map<string, DefaultMatchResultItem[]> instead of a Record<string, DefaultMatchResultItem[]>, and updated the grouping logic to use Map methods.
  • Updated the rendering logic to iterate over the keys and values of the Map using Array.from(normalizedSuggestions.keys()) and normalizedSuggestions.get(group) instead of object property access.

Related Issue

#2585

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings September 11, 2025 09:59
@netlify
Copy link

netlify bot commented Sep 11, 2025

Deploy Preview for rspress-v2 ready!

Name Link
🔨 Latest commit c947252
🔍 Latest deploy log https://app.netlify.com/projects/rspress-v2/deploys/68c29e30739edc000803ccc8
😎 Deploy Preview https://deploy-preview-2586--rspress-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes an issue with the suggestions object implementation by replacing a plain JavaScript object with a Map to properly handle keys with constructor properties.

  • Replaces Record<string, DefaultMatchResultItem[]> with Map<string, DefaultMatchResultItem[]>
  • Updates all object access patterns to use Map methods (.has(), .get(), .set())
  • Changes iteration from Object.keys() to Array.from(map.keys())

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

replace ? -> !

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@SoonIter SoonIter merged commit 1385860 into main Sep 11, 2025
8 checks passed
@SoonIter SoonIter deleted the fix/normalize-suggestion-with-keywords branch September 11, 2025 10:32
@SoonIter
Copy link
Member

Interesting, anothor option is Object.create(null)

Map is better than Object.create(null) I think. LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants