From 268e40d5225758e910ebb6ec19612152531e809c Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 7 May 2024 15:53:29 -0700 Subject: [PATCH] Fix bug in which _props is undefined. --- docs/package-lock.json | 2 +- docs/package.json | 2 +- package-lock.json | 4 ++-- src/index.tsx | 27 ++++++++++++++++++--------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 7c294b5..3f7ec25 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -14,7 +14,7 @@ }, "..": { "name": "@vectara/react-search", - "version": "0.0.15", + "version": "1.0.1", "license": "Apache-2.0", "dependencies": { "@testing-library/react-hooks": "^8.0.1", diff --git a/docs/package.json b/docs/package.json index 00c3ab0..12dc313 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,7 +5,7 @@ "main": "build.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "docs": "node docsServer.js", + "docs": "npm run buildDocs && node docsServer.js", "buildDocs": "node build.js" }, "author": "", diff --git a/package-lock.json b/package-lock.json index f2fd0e7..7a99e33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@vectara/react-search", - "version": "0.0.15", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@vectara/react-search", - "version": "0.0.15", + "version": "1.0.1", "license": "Apache-2.0", "dependencies": { "@testing-library/react-hooks": "^8.0.1", diff --git a/src/index.tsx b/src/index.tsx index 7a7fc65..92f117a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -96,13 +96,16 @@ const ReactSearchInternal = ({ addPreviousSearch(query); const searchId = ++searchCount.current; - const { searchResults, summary } = await fetchSearchResults(query, isSummaryEnabled); - - if (searchId === searchCount.current) { - setSearchResults(searchResults); - setSummary(summary); - setSelectedResultIndex(undefined); - selectedResultRef.current = null; + try { + const { searchResults, summary } = await fetchSearchResults(query, isSummaryEnabled); + if (searchId === searchCount.current) { + setSearchResults(searchResults); + setSummary(summary); + setSelectedResultIndex(undefined); + selectedResultRef.current = null; + } + } catch (error) { + console.log("ReactSearch error:" + error); } }; @@ -397,8 +400,14 @@ class ReactSearchWebComponent extends HTMLElement { window.customElements.get("react-search") || window.customElements.define("react-search", ReactSearchWebComponent); export const ReactSearch = (props: Props) => { - _props = props; + // This is magic. If we remove this, then in Console _props somehow ends up + // being undefined when consumed by ReactSearchWebComponent. We found that this + // conditional ensures _props is always set, though it doesn't look like props + // is ever undefined. + if (props) { + _props = props; + } // @ts-ignore - return ; + return ; };