separate context for different pages with pathname#106
separate context for different pages with pathname#106mjBayati wants to merge 1 commit intome4502:mainfrom
Conversation
|
This change appears to make sense, I just have two concerns;
|
|
thanks for your review, especially about your wise comment on second, I think for using by the way, what i understand from gatsby-build and gatsb-ssr api's, the best solution is to separate contexts, but if there is better solution to avoid thanks, |
|
is there any update ? |
|
My main concern here is that this update would break any existing sites with a large number of pages, if it's causing major memory leaks. If it doesn't actually cause a large increase for a few hundred thousand pages with a normal amount of meta tags being added, I'd be okay with the change as-is |
| import { HelmetProvider, HelmetServerState } from 'react-helmet-async'; | ||
|
|
||
| const context: { helmet?: HelmetServerState } = {}; | ||
| const context: {[pathname: string]: { helmet?: HelmetServerState }} = {}; |
There was a problem hiding this comment.
Is this correctly typed?
On Line #14 we're checking if (helmet) and then accessing helmet.base but it's actually helmet.helmet.base now?
npm ERR! src/gatsby-ssr.tsx(16,39): error TS2339: Property 'title' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(18,20): error TS2339: Property 'priority' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(19,20): error TS2339: Property 'meta' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(20,20): error TS2339: Property 'link' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(21,20): error TS2339: Property 'style' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(22,20): error TS2339: Property 'script' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(23,20): error TS2339: Property 'noscript' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(32,34): error TS2339: Property 'htmlAttributes' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
npm ERR! src/gatsby-ssr.tsx(33,34): error TS2339: Property 'bodyAttributes' does not exist on type '{ helmet?: HelmetServerState | undefined; }'.
There was a problem hiding this comment.
Actually this typing is probably correct but we should access context on onRenderBody like this:
export const onRenderBody: GatsbySSR['onRenderBody'] = ({
pathname,
setHeadComponents,
setHtmlAttributes,
setBodyAttributes,
}: RenderBodyArgs): void => {
const { helmet } = context[pathname]
|
I implemented these changes and my own remarks on my own fork as I needed to get this fixed asap. We have about 30K pages but we're not really limited by memory afaik. So far everything is working but we haven't made any extensive testing |
fix issue #97.
by separating contexts of each page on rendering root element in
gatsby-ssr