Skip to content
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

Merged
merged 5 commits into from
Jan 19, 2023
Merged

fix(gatsby): pass serverData to Head #37500

merged 5 commits into from
Jan 19, 2023

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Jan 19, 2023

Description

Pass serverData as prop (from getServerData) to Head

Documentation

Related Issues

[ch-60342]
#35841 (comment)

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 19, 2023
@pieh pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 19, 2023
Comment on lines -159 to +163
export type HeadProps<DataType = object, PageContextType = object> = {
export type HeadProps<
DataType = object,
PageContextType = object,
ServerDataType = object
> = {
Copy link
Contributor Author

@pieh pieh Jan 19, 2023

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):

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
}

Copy link
Contributor

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,
Copy link
Contributor Author

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

@pieh pieh marked this pull request as ready for review January 19, 2023 11:58
@LekoArts LekoArts added the topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) label Jan 19, 2023
@pieh pieh merged commit 0017375 into master Jan 19, 2023
@pieh pieh deleted the head-server-data branch January 19, 2023 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants