Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in which _props is undefined. #66

Merged
merged 1 commit into from
May 7, 2024
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
2 changes: 1 addition & 1 deletion docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "build.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docs": "node docsServer.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this change because when I ran npm run docs, the docs site was using an outdated version of ReactSearch.

"docs": "npm run buildDocs && node docsServer.js",
"buildDocs": "node build.js"
},
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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 <react-search serializedprops={JSON.stringify(props)} />;
return <react-search serializedprops={JSON.stringify(_props)} />;
};
Loading