-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separate context for different pages with pathname #106
base: main
Are you sure you want to change the base?
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 |
@@ -2,7 +2,7 @@ import { GatsbySSR, RenderBodyArgs, WrapRootElementNodeArgs } from 'gatsby'; | |||
import React from 'react'; | |||
import { HelmetProvider, HelmetServerState } from 'react-helmet-async'; | |||
|
|||
const context: { helmet?: HelmetServerState } = {}; | |||
const context: {[pathname: string]: { helmet?: HelmetServerState }} = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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