Skip to content

fix(removeHighlightTags): prevent destructuring undefined object#1039

Merged
shortcuts merged 3 commits into
nextfrom
fix/removeHighlightTags
Aug 19, 2021
Merged

fix(removeHighlightTags): prevent destructuring undefined object#1039
shortcuts merged 3 commits into
nextfrom
fix/removeHighlightTags

Conversation

@shortcuts

@shortcuts shortcuts commented Aug 19, 2021

Copy link
Copy Markdown
Member

Summary

In case the indexing isn't optimal, an error is thrown as we are destructuring a possibly null lvl0.

Reproduction
This can happen when using DocSearch with a Netlify x Algolia Crawler index, but also with a DocSearch index: Search for ge in this sandbox

Solution

We now use getAttributeValueByPath to retrieve the attribute value, and fallback to an empty string if not found (alternatively, we could provide a default value such as Documentation).

@codesandbox-ci

codesandbox-ci Bot commented Aug 19, 2021

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2673afc:

Sandbox Source
Vanilla Configuration
elegant-curie-76y18 PR

Comment thread packages/docsearch-react/src/utils/removeHighlightTags.ts Outdated
Comment thread packages/docsearch-react/src/utils/getAttributeValueByPath.ts Outdated
Comment thread packages/docsearch-react/src/utils/removeHighlightTags.ts Outdated
Co-authored-by: Haroen Viaene <hello@haroen.me>
@shortcuts shortcuts merged commit 6a6f7f6 into next Aug 19, 2021
@shortcuts shortcuts deleted the fix/removeHighlightTags branch August 19, 2021 16:19
@pixelastic

Copy link
Copy Markdown
Contributor

Thanks @Haroenv and @shortcuts

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