Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

fix(Highlight): only warn once for possibly missing highlighting #386

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/Highlight.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getPropertyByPath } from '../util/object';
import { warn } from '../util/warn';

export default {
functional: true,
Expand All @@ -20,8 +21,8 @@ export default {
const attributeValue = getPropertyByPath(result, attributePath);

if (process.env.NODE_ENV !== 'production' && attributeValue === undefined) {
throw new Error(
`The "${attributeName}" attribute is currently not configured to be highlighted in Algolia.
warn(
`The "${attributeName}" attribute might currently not be configured to be highlighted in Algolia.
See https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/.`
);
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const cache = new Set();

export function warn(message) {
if (cache.has(message)) return;
cache.add(message);
// eslint-disable-next-line no-console
console.warn(message);
}