From 7aa3126cb0e31b2bf3baf90ca8f6691627730848 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 2 Feb 2018 10:03:12 +0100 Subject: [PATCH] fix(Highlight): only warn once for possibly missing highlighting (algolia/vue-instantsearch#386) fixes algolia/vue-instantsearch#385 --- packages/vue-instantsearch/src/components/Highlight.js | 5 +++-- packages/vue-instantsearch/src/util/warn.js | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 packages/vue-instantsearch/src/util/warn.js diff --git a/packages/vue-instantsearch/src/components/Highlight.js b/packages/vue-instantsearch/src/components/Highlight.js index 145fdbea88..af3f39aa1c 100644 --- a/packages/vue-instantsearch/src/components/Highlight.js +++ b/packages/vue-instantsearch/src/components/Highlight.js @@ -1,4 +1,5 @@ import { getPropertyByPath } from '../util/object'; +import { warn } from '../util/warn'; export default { functional: true, @@ -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/.` ); } diff --git a/packages/vue-instantsearch/src/util/warn.js b/packages/vue-instantsearch/src/util/warn.js new file mode 100644 index 0000000000..db4c319c58 --- /dev/null +++ b/packages/vue-instantsearch/src/util/warn.js @@ -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); +}