Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
fix(search): 🐛 fix issue with performance not avaialble during SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Aug 12, 2020
1 parent e7dd75f commit 85b92f5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/Search/localsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import { StaticQuery, graphql } from 'gatsby';

const Results = ({ q }) => <SearchStatus noHits={true} searching={false} query={q} />;

const getPerformance = () => {
if (typeof window !== `undefined` && window.performance) {
return window.performance;
}
return {
now: () => new Date().getMilliseconds()
}
}

const calculatePage = (results, page) => {
const hitsPerPage = config.features.search.hitsPerPage;
const startIdx = hitsPerPage * page - hitsPerPage;
Expand All @@ -19,6 +28,7 @@ const calculatePage = (results, page) => {
};

const search = (query, index, store, page) => {
const performance = getPerformance();
const t1 = performance.now();
const results = useFlexSearch(query, index, JSON.parse(store));
const maxResults =
Expand Down

0 comments on commit 85b92f5

Please sign in to comment.