Skip to content

Commit 2ca0678

Browse files
committed
Misc per-page-manifest fixes (gatsbyjs#14413)
* use path.join for static-entry page-data path * add pathContext back to static-entry props (fix regression)
1 parent 8c9847d commit 2ca0678

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

e2e-tests/production-runtime/cypress/integration/1-production.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ describe(`Production build tests`, () => {
8383
.should(`exist`)
8484
})
8585

86+
it(`should pass pathContext to props`, () => {
87+
cy.visit(`/path-context`).waitForRouteChange()
88+
89+
// `bar` is set in gatsby-node createPages
90+
cy.getTestElement(`path-context-foo`).contains(`bar`)
91+
})
92+
8693
it(`Uses env vars`, () => {
8794
cy.visit(`/env-vars`).waitForRouteChange()
8895

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
exports.onCreatePage = ({ page, actions }) => {
2-
if (page.path === `/client-only-paths/`) {
3-
// create client-only-paths
4-
page.matchPath = `/client-only-paths/*`
5-
actions.createPage(page)
6-
} else if (page.path === `/`) {
7-
// use index page as template
8-
// (mimics)
9-
actions.createPage({
10-
...page,
11-
path: `/duplicated`,
12-
context: {
13-
DOMMarker: `duplicated`,
14-
},
15-
})
2+
switch (page.path) {
3+
case `/client-only-paths/`:
4+
// create client-only-paths
5+
page.matchPath = `/client-only-paths/*`
6+
actions.createPage(page)
7+
break
8+
9+
case `/path-context/`:
10+
actions.createPage({
11+
...page,
12+
context: {
13+
foo: `bar`,
14+
},
15+
})
16+
break
17+
18+
case `/`:
19+
// use index page as template
20+
// (mimics)
21+
actions.createPage({
22+
...page,
23+
path: `/duplicated`,
24+
context: {
25+
DOMMarker: `duplicated`,
26+
},
27+
})
28+
break
1629
}
1730
}

e2e-tests/production-runtime/src/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ const IndexPage = ({ pageContext }) => (
5151
Compilation Hash Page
5252
</Link>
5353
</li>
54+
<li>
55+
<Link to="/path-context/" data-testid="path-context">
56+
Path Context
57+
</Link>
58+
</li>
5459
</ul>
5560
</Layout>
5661
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
3+
import Layout from '../components/layout'
4+
import InstrumentPage from '../utils/instrument-page'
5+
6+
const PathContextPage = ({ pathContext }) => (
7+
<Layout>
8+
<h1>Hello from a page that uses the old pathContext</h1>
9+
<p>It was deprecated in favor of pageContext, but is still supported</p>
10+
<p>
11+
page.pathContext.foo =
12+
<span data-testid="path-context-foo">{pathContext.foo}</span>
13+
</p>
14+
</Layout>
15+
)
16+
17+
export default InstrumentPage(PathContextPage)

packages/gatsby/cache-dir/__tests__/static-entry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react"
22
import fs from "fs"
3+
const { join } = require(`path`)
34

45
import DevelopStaticEntry from "../develop-static-entry"
56

@@ -33,7 +34,10 @@ jest.mock(
3334
const MOCK_FILE_INFO = {
3435
[`${process.cwd()}/public/webpack.stats.json`]: `{}`,
3536
[`${process.cwd()}/public/chunk-map.json`]: `{}`,
36-
[`${process.cwd()}/public/page-data/about/page-data.json`]: JSON.stringify({
37+
[join(
38+
process.cwd(),
39+
`/public/page-data/about/page-data.json`
40+
)]: JSON.stringify({
3741
componentChunkName: `page-component---src-pages-test-js`,
3842
path: `/about/`,
3943
webpackCompilationHash: `1234567890abcdef1234`,

packages/gatsby/cache-dir/static-entry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ export default (pagePath, callback) => {
152152
const props = {
153153
...this.props,
154154
...pageData.result,
155+
// pathContext was deprecated in v2. Renamed to pageContext
156+
pathContext: pageData.result ? pageData.result.pageContext : undefined,
155157
}
156158

157159
const pageElement = createElement(

0 commit comments

Comments
 (0)