Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created February 16, 2021 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamieMason/ca8bfa0370873ba9cc0d6cbcae3db63e to your computer and use it in GitHub Desktop.
Save JamieMason/ca8bfa0370873ba9cc0d6cbcae3db63e to your computer and use it in GitHub Desktop.
TODO getServerSideProps leaking server deps into client bundle
import type { GetServerSideProps, NextPage } from 'next';
import Head from 'next/head';
import React from 'react';
import { SearchPageComponent } from './search-page-component';
import type { Props } from './search-page-props';
export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
try {
if (typeof window === 'undefined') {
const { getSearchPageProps } = await import('./search-page-props');
const props = await getSearchPageProps(ctx);
return { props };
}
} catch (err) {
return { notFound: true };
}
return { notFound: true };
};
export const SearchPage: NextPage<Props> = ({ algoliaListing, searchPage, siteLayout }) => (
<React.Fragment>
<Head>
<title>{searchPage.meta.title}</title>
<meta content={searchPage.meta.description} name="description" />
<link href={searchPage.meta.canonical} rel="canonical" />
</Head>
<SearchPageComponent
algoliaListing={algoliaListing}
searchPage={searchPage}
siteLayout={siteLayout}
/>
</React.Fragment>
);
export default SearchPage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment