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: allow dsg/ssr renders without access to datastore if it's not required #38974

Merged
merged 13 commits into from
May 17, 2024
Merged
Prev Previous commit
Next Next commit
findPageByPath renaming
pieh committed May 16, 2024

Unverified

No user is associated with the committer email.
commit ed74e49760ae2117f545573864eb69458fd7375c
6 changes: 3 additions & 3 deletions packages/gatsby/src/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -202,7 +202,7 @@ module.exports = async (program: IServeProgram): Promise<void> => {
try {
const { GraphQLEngine } =
require(graphqlEnginePath) as typeof import("../schema/graphql-engine/entry")
const { getData, renderPageData, renderHTML } =
const { getData, renderPageData, renderHTML, findEnginePageByPath } =
require(pageSSRModule) as typeof import("../utils/page-ssr-module/entry")
const graphqlEngine = new GraphQLEngine({
dbPath: path.posix.join(
@@ -222,7 +222,7 @@ module.exports = async (program: IServeProgram): Promise<void> => {
}

const potentialPagePath = reverseFixedPagePath(requestedPagePath)
const page = graphqlEngine.findPageByPath(potentialPagePath)
const page = findEnginePageByPath(potentialPagePath)

if (page && (page.mode === `DSG` || page.mode === `SSR`)) {
const requestActivity = report.phantomActivity(
@@ -272,7 +272,7 @@ module.exports = async (program: IServeProgram): Promise<void> => {
router.use(async (req, res, next) => {
if (req.accepts(`html`)) {
const potentialPagePath = req.path
const page = graphqlEngine.findPageByPath(potentialPagePath)
const page = findEnginePageByPath(potentialPagePath)
if (page && (page.mode === `DSG` || page.mode === `SSR`)) {
const requestActivity = report.phantomActivity(
`request for "${req.path}"`
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/graphql-engine/entry.ts
Original file line number Diff line number Diff line change
@@ -196,7 +196,7 @@ export class GraphQLEngine {
}

/**
* @deprecated use findPageByPath exported from page-ssr module instead
* @deprecated use findEnginePageByPath exported from page-ssr module instead
*/
public findPageByPath(pathName: string): IGatsbyPage | undefined {
// adapter so `findPageByPath` use SitePage nodes in datastore
8 changes: 4 additions & 4 deletions packages/gatsby/src/utils/page-ssr-module/entry.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ import { ICollectedSlice } from "../babel/find-slices"
import { createHeadersMatcher } from "../adapter/create-headers"
import { MUST_REVALIDATE_HEADERS } from "../adapter/constants"
import { getRoutePathFromPage } from "../adapter/get-route-path"
import { findPageByPath as findPageByPathInner } from "../find-page-by-path"
import { findPageByPath } from "../find-page-by-path"

export interface ITemplateDetails {
query: string
@@ -144,7 +144,7 @@ export async function getData(arg: IGetDataArgs): Promise<ISSRData> {
potentialPagePath = getPagePathFromPageDataPath(pathName) || pathName

// 1. Find a page for pathname
const maybePage = findPageByPath(potentialPagePath)
const maybePage = findEnginePageByPath(potentialPagePath)

if (!maybePage) {
// page not found, nothing to run query for
@@ -526,6 +526,6 @@ const stateWithPages = {
pages: new Map(GATSBY_PAGES),
} as unknown as IGatsbyState

export function findPageByPath(pathName: string): EnginePage | undefined {
return findPageByPathInner(stateWithPages, pathName, false)
export function findEnginePageByPath(pathName: string): EnginePage | undefined {
return findPageByPath(stateWithPages, pathName, false)
}
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/page-ssr-module/lambda.ts
Original file line number Diff line number Diff line change
@@ -225,7 +225,7 @@ type GraphQLEngineType =
const { GraphQLEngine } =
require(`../query-engine`) as typeof import("../../schema/graphql-engine/entry")

const { getData, renderPageData, renderHTML, findPageByPath } =
const { getData, renderPageData, renderHTML, findEnginePageByPath } =
require(`./index`) as typeof import("./entry")

const streamPipeline = promisify(pipeline)
@@ -442,7 +442,7 @@ function getPage(pathname: string): IPageInfo | undefined {

const { isPageData, pagePath } = pathInfo

const page = findPageByPath(pagePath)
const page = findEnginePageByPath(pagePath)
if (!page) {
return undefined
}