File tree 4 files changed +37
-1
lines changed
e2e-tests/production-runtime
cypress/integration/head-function-export
src/pages/head-function-export
packages/gatsby/cache-dir/head
4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
1
+ import headFunctionExportSharedData from "../../../shared-data/head-function-export.js"
2
+
3
+ it ( `Page with Head Export that uses useLocation works` , ( ) => {
4
+ cy . visit ( headFunctionExportSharedData . page . pageWithUseLocation ) . waitForRouteChange ( )
5
+
6
+ cy . getTestElement ( `location-pathname-in-template` )
7
+ . invoke ( `text` )
8
+ . then ( text => {
9
+ cy . getTestElement ( `location-pathname-in-head` )
10
+ . invoke ( `attr` , `content` )
11
+ . should ( 'equal' , text )
12
+ } )
13
+ } )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const page = {
12
12
invalidElements : `${ path } /invalid-elements/` ,
13
13
fsRouteApi : `${ path } /fs-route-api/` ,
14
14
deduplication : `${ path } /deduplication/` ,
15
+ pageWithUseLocation : `${ path } /page-with-uselocation/` ,
15
16
}
16
17
17
18
const data = {
Original file line number Diff line number Diff line change
1
+ import * as React from "react"
2
+ import { useLocation } from '@gatsbyjs/reach-router' ;
3
+
4
+ export default function HeadFunctionExportWithUseLocation ( ) {
5
+ const location = useLocation ( ) ;
6
+
7
+ return (
8
+ < >
9
+ < h1 > I test that Head export with useLocation hook works</ h1 >
10
+ < p data-testid = "location-pathname-in-template" > { location . pathname } </ p >
11
+ </ >
12
+ )
13
+ }
14
+
15
+ export function Head ( ) {
16
+ const location = useLocation ( ) ;
17
+
18
+ return < meta data-testid = "location-pathname-in-head" name = "location" content = { location . pathname } />
19
+ }
Original file line number Diff line number Diff line change 1
1
import React from "react"
2
2
import { useEffect } from "react"
3
3
import { StaticQueryContext } from "gatsby"
4
+ import { LocationProvider } from "@gatsbyjs/reach-router"
4
5
import { reactDOMUtils } from "../react-dom-utils"
5
6
import { FireCallbackInEffect } from "./components/fire-callback-in-effect"
6
7
import { VALID_NODE_NAMES } from "./constants"
@@ -81,7 +82,9 @@ export function headHandlerForBrowser({
81
82
// In Prod we only call onHeadRendered in FireCallbackInEffect to render to head
82
83
< FireCallbackInEffect callback = { onHeadRendered } >
83
84
< StaticQueryContext . Provider value = { staticQueryResults } >
84
- < Head { ...filterHeadProps ( pageComponentProps ) } />
85
+ < LocationProvider >
86
+ < Head { ...filterHeadProps ( pageComponentProps ) } />
87
+ </ LocationProvider >
85
88
</ StaticQueryContext . Provider >
86
89
</ FireCallbackInEffect > ,
87
90
hiddenRoot
You can’t perform that action at this time.
0 commit comments