From 1023f45e9fd6eb27ddd746ee311a785eaa27f557 Mon Sep 17 00:00:00 2001 From: Tim Glaser Date: Thu, 25 Jun 2020 09:40:12 -0700 Subject: [PATCH] feat: SSR for page specific providers --- gatsby-browser.js | 20 ++------------------ gatsby-ssr.js | 5 ++++- gatsby/wrap-page-element.js | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 gatsby/wrap-page-element.js diff --git a/gatsby-browser.js b/gatsby-browser.js index 39a4e3c3a..76ee9ffdd 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -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 ( - - - {element} - - - ); -}; +exports.wrapPageElement = wrapPageElement; diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 7bc45280e..6a1e8f56a 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -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, diff --git a/gatsby/wrap-page-element.js b/gatsby/wrap-page-element.js new file mode 100644 index 000000000..1f0f8d650 --- /dev/null +++ b/gatsby/wrap-page-element.js @@ -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 ( + + + {element} + + + ); +};