-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby): pass serverData to Head #37500
Conversation
export type HeadProps<DataType = object, PageContextType = object> = { | ||
export type HeadProps< | ||
DataType = object, | ||
PageContextType = object, | ||
ServerDataType = object | ||
> = { |
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.
Setup copied from PageProps
(tho not sure if I should also add Location
part, we should decide on that, because generics are position arguments, so trying to add it later would be a problem):
gatsby/packages/gatsby/index.d.ts
Lines 87 to 154 in fe65c29
export type PageProps< | |
DataType = object, | |
PageContextType = object, | |
LocationState = WindowLocation["state"], | |
ServerDataType = object | |
> = { | |
/** The path for this current page */ | |
path: string | |
/** The URI for the current page */ | |
uri: string | |
/** An extended version of window.document which comes from @react/router */ | |
location: WindowLocation<LocationState> | |
/** A way to handle programmatically controlling navigation */ | |
navigate: NavigateFn | |
/** You can't get passed children as this is the root user-land component */ | |
children: undefined | |
/** The URL parameters when the page has a `matchPath` */ | |
params: Record<string, string> | |
/** Holds information about the build process for this component */ | |
pageResources: { | |
component: React.Component | |
json: { | |
data: DataType | |
pageContext: PageContextType | |
} | |
page: { | |
componentChunkName: string | |
path: string | |
webpackCompilationHash: string | |
matchPath?: string | |
} | |
} | |
/** | |
* Data passed into the page via an exported GraphQL query. To set up this type | |
* you need to use [generics](https://www.typescriptlang.org/play/#example/generic-functions), | |
* see below for an example | |
* | |
* @example | |
* | |
* import {PageProps} from "gatsby" | |
* | |
* type IndexQueryProps = { downloadCount: number } | |
* type IndexPageProps = PageProps<IndexQueryProps> | |
* | |
* export default (props: IndexPageProps) => { | |
* .. | |
* | |
*/ | |
data: DataType | |
/** | |
* A context object which is passed in during the creation of the page. Can be extended if you are using | |
* `createPage` yourself using generics: | |
* | |
* @example | |
* | |
* import {PageProps} from "gatsby" | |
* | |
* type IndexQueryProps = { downloadCount: number } | |
* type LocaleLookUpInfo = { translationStrings: any } & { langKey: string, slug: string } | |
* type IndexPageProps = PageProps<IndexQueryProps, LocaleLookUpInfo> | |
* | |
* export default (props: IndexPageProps) => { | |
* .. | |
*/ | |
pageContext: PageContextType | |
/** Data passed into the page via the [getServerData](https://www.gatsbyjs.com/docs/reference/rendering-options/server-side-rendering/) SSR function. */ | |
serverData: ServerDataType | |
} |
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.
With Head the location will only ever be pathname
so there won't be a need for LocationState
generic
So we can skip that
@@ -11,6 +11,7 @@ export function filterHeadProps(input) { | |||
}, | |||
params: input.params, | |||
data: input.data || {}, | |||
serverData: input.serverData, |
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.
this is entire fix, rest is just added tests and updated HeadProps type
Description
Pass
serverData
as prop (fromgetServerData
) toHead
Documentation
Related Issues
[ch-60342]
#35841 (comment)