Skip to content

Commit

Permalink
feat: SSR for page specific providers
Browse files Browse the repository at this point in the history
  • Loading branch information
timglaser committed Jun 25, 2020
1 parent af7aba0 commit 1023f45
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
20 changes: 2 additions & 18 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/

const React = require('react');
const BreadcrumbContext = require('./src/components/BreadcrumbContext')
.BreadcrumbContext;
const PageContext = require('./src/components/PageContext').PageContext;
const wrapPageElement = require('./gatsby/wrap-page-element').default;

const createBreadcrumbs = require('./src/utils/create-breadcrumbs').default;
const pages = require('./src/data/sidenav.json');

exports.wrapPageElement = ({ element, props }) => {
const crumbs = createBreadcrumbs(props.path, pages);

return (
<PageContext.Provider value={props.pageContext}>
<BreadcrumbContext.Provider value={crumbs}>
{element}
</BreadcrumbContext.Provider>
</PageContext.Provider>
);
};
exports.wrapPageElement = wrapPageElement;
5 changes: 4 additions & 1 deletion gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/

// This is needed to ensure the NR1 SDK can load properly
const React = require('react');
const { JS_BUNDLE } = require('./src/utils/sdk');
const wrapPageElement = require('./gatsby/wrap-page-element').default;

exports.wrapPageElement = wrapPageElement;

// This is needed to ensure the NR1 SDK can load properly
exports.onPreRenderHTML = ({
getHeadComponents,
replaceHeadComponents,
Expand Down
19 changes: 19 additions & 0 deletions gatsby/wrap-page-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const React = require('react');
const BreadcrumbContext = require('../src/components/BreadcrumbContext')
.BreadcrumbContext;
const PageContext = require('../src/components/PageContext').PageContext;

const createBreadcrumbs = require('../src/utils/create-breadcrumbs').default;
const pages = require('../src/data/sidenav.json');

export default ({ element, props }) => {
const crumbs = createBreadcrumbs(props.path, pages);

return (
<PageContext.Provider value={props.pageContext}>
<BreadcrumbContext.Provider value={crumbs}>
{element}
</BreadcrumbContext.Provider>
</PageContext.Provider>
);
};

0 comments on commit 1023f45

Please sign in to comment.