Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions integration-tests/artifacts/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,40 @@ function assertHTMLCorrectness(runNumber) {
})
})
})

describe(`/changing-context/`, () => {
let pageDataContent
let htmlContent
beforeAll(() => {
pageDataContent = fs.readJsonSync(
path.join(
process.cwd(),
`public`,
`page-data`,
`changing-context`,
`page-data.json`
)
)

htmlContent = fs.readFileSync(
path.join(process.cwd(), `public`, `changing-context`, `index.html`),
`utf-8`
)
})

it(`html is correctly generated using fresh page context`, () => {
// remove <!-- --> from html content string as that's impl details of react ssr
expect(htmlContent.replace(/<!-- -->/g, ``)).toContain(
`Dummy page for runNumber: ${runNumber}`
)
})

it(`page-data is correctly generated using fresh page context`, () => {
expect(pageDataContent.result.pageContext).toEqual({
dummyId: `runNumber: ${runNumber}`,
})
})
})
}

function assertNodeCorrectness(runNumber) {
Expand Down Expand Up @@ -486,6 +520,7 @@ describe(`Second run (different pages created, data changed)`, () => {
`/static-query-result-tracking/should-invalidate/`,
`/page-query-template-change/`,
`/stale-pages/sometimes-i-have-trailing-slash-sometimes-i-dont/`,
`/changing-context/`,
]

const expectedPagesToRemainFromPreviousBuild = [
Expand All @@ -495,6 +530,7 @@ describe(`Second run (different pages created, data changed)`, () => {
`/static-query-result-tracking/stable/`,
`/static-query-result-tracking/rerun-query-but-dont-recreate-html/`,
`/page-that-will-have-trailing-slash-removed`,
`/stateful-page-not-recreated-in-third-run/`,
]

const expectedPages = [
Expand Down Expand Up @@ -579,6 +615,7 @@ describe(`Third run (js change, all pages are recreated)`, () => {
`/stale-pages/only-in-first/`,
`/page-query-dynamic-1/`,
`/page-query-dynamic-2/`,
`/stateful-page-not-recreated-in-third-run/`,
]

let changedFileOriginalContent
Expand Down Expand Up @@ -664,6 +701,7 @@ describe(`Fourth run (gatsby-browser change - cache get invalidated)`, () => {
const expectedPages = [
`/stale-pages/only-not-in-first`,
`/page-query-dynamic-4/`,
`/stateful-page-not-recreated-in-third-run/`,
]

const unexpectedPages = [
Expand Down
20 changes: 20 additions & 0 deletions integration-tests/artifacts/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ exports.createPages = async ({ actions, graphql }) => {
}`
)

actions.createPage({
path: `/changing-context/`,
component: require.resolve(`./src/templates/dummy`),
context: {
dummyId: `runNumber: ${runNumber}`,
},
})

const { data } = await graphql(`
{
allDepPageQuery {
Expand All @@ -189,6 +197,18 @@ exports.createPages = async ({ actions, graphql }) => {
}
}

exports.createPagesStatefully = async ({ actions }) => {
if (runNumber !== 3) {
actions.createPage({
path: `/stateful-page-not-recreated-in-third-run/`,
component: require.resolve(`./src/templates/dummy`),
context: {
dummyId: `stateful-page`,
},
})
}
}

exports.onPreBuild = () => {
console.log(`[test] onPreBuild`)
changedBrowserCompilationHash = `not-changed`
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
sourceNodes,
buildSchema,
createPages,
createPagesStatefully,
extractQueries,
writeOutRedirects,
postBootstrap,
Expand All @@ -32,9 +31,12 @@ export async function bootstrap(

const parentSpan = tracer.startSpan(`bootstrap`, spanArgs)

const bootstrapContext: IBuildContext = {
const bootstrapContext: IBuildContext & {
shouldRunCreatePagesStatefully: boolean
} = {
...initialContext,
parentSpan,
shouldRunCreatePagesStatefully: true,
}

const context = {
Expand All @@ -54,8 +56,6 @@ export async function bootstrap(

await createPages(context)

await createPagesStatefully(context)

await handleStalePageData()

await rebuildSchemaWithSitePage(context)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/query/__tests__/data-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ describe(`query caching between builds`, () => {
}, 99999)
})

describe.skip(`Changing page context invalidates page queries`, () => {
describe(`Changing page context invalidates page queries`, () => {
beforeAll(() => {
let pageChangeCounter = 1
let nodeChangeCounter = 1
Expand Down
17 changes: 17 additions & 0 deletions packages/gatsby/src/redux/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ Object {
},
},
"pageDataStats": Map {},
"pages": Map {
"/my-sweet-new-page/" => Object {
"component": "/Users/username/dev/site/src/templates/my-sweet-new-page.js",
"componentChunkName": "component---users-username-dev-site-src-templates-my-sweet-new-page-js",
"componentPath": "/Users/username/dev/site/src/templates/my-sweet-new-page.js",
"context": Object {
"id": "123456",
},
"internalComponentName": "Component/my-sweet-new-page/",
"isCreatedByStatefulCreatePages": false,
"matchPath": undefined,
"path": "/my-sweet-new-page/",
"pluginCreatorId": "",
"pluginCreator___NODE": "",
"updatedAt": 1,
},
},
"pendingPageDataWrites": Object {
"pagePaths": Set {},
},
Expand Down
Loading