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

feat(gatsby): page engine #33067

Merged
merged 7 commits into from
Sep 7, 2021
Merged

feat(gatsby): page engine #33067

merged 7 commits into from
Sep 7, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Sep 6, 2021

I suggest to use "Hide whitespace changes" in diff viewer - https://github.com/gatsbyjs/gatsby/pull/33067/files?diff=unified&w=1

Building on top of GraphQL Engine introduced in #33030

Description

This feature is disabled by default. Only available when building gatsby itself with COMPILER_OPTIONS="GATSBY_MAJOR=4"

This adds generation of "page engine" - importable standalone module that allows generation of page-data and html content. It uses "query engine" (introduced in #33030 ) under the hood.

Example usage (after initial gatsby build):

const { GraphQLEngine } = require(`./.cache/query-engine`)
const { getData, renderHTML, renderPageData } = require(`./.cache/page-ssr`)

const graphqlEngine = new GraphQLEngine({
  dbPath: process.cwd() + `/.cache/data/datastore`,
})

async function run() {
  const data = await getData({ graphqlEngine, pathName })
  const pageData = await renderPageData({ data })
  const html = await renderHTML({ data, pageData })

  console.log({ pageData, html })
}

run()

[ch37670]

Fixes #32892

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 6, 2021
@pieh pieh marked this pull request as ready for review September 6, 2021 14:38
@pieh pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 6, 2021
@@ -0,0 +1,153 @@
import * as path from "path"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted to separate module from packages/gatsby/src/utils/worker/child/render-html.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify - we need to have it as a separate module because we re-use it later in bundle-webpack, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, possibly we could revert this split because we don't use it in engine itself. But it's still beneficial because we don't have to load more things from workers code than needed (child/render-html.ts is not loaded by main process, just by html/pqr worker processes)

@@ -0,0 +1,50 @@
import { IGatsbyPage } from "../redux/types"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted to separate module from packages/gatsby/src/utils/page-data.ts + addition of getPagePathFromPageDataPath to reverse /page-data/<page-path>/page-data.json to <page-path>

@@ -0,0 +1,89 @@
import fs from "fs-extra"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted to separate module from packages/gatsby/src/utils/worker/child/render-html.ts

vladar
vladar previously approved these changes Sep 7, 2021
Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

vladar
vladar previously approved these changes Sep 7, 2021
@vladar vladar added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Sep 7, 2021
@gatsbybot gatsbybot merged commit ce5af85 into master Sep 7, 2021
@gatsbybot gatsbybot deleted the page-engine branch September 7, 2021 12:59
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
* feat(gatsby): page engine

* extract page-data helpers used in page engine to separate module, to not bundle unneeded pieces

* fix develop

* update page engine webpack config similarly as done in graphql engine

* Update packages/gatsby/src/utils/page-ssr-module/bundle-webpack.ts

Co-authored-by: Vladimir Razuvaev <[email protected]>

* Update packages/gatsby/src/utils/page-data-helpers.ts

Co-authored-by: Vladimir Razuvaev <[email protected]>

* Update packages/gatsby/src/utils/page-data-helpers.ts

Co-authored-by: Vladimir Razuvaev <[email protected]>

Co-authored-by: Vladimir Razuvaev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

having " in page path results in a build crash: Query was not run and no cached result was found.
3 participants