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

refactor(websocket): unify page-data emitting #25190

Merged
merged 1 commit into from
Jun 22, 2020
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
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/query-result-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class PageQueryStore extends React.Component {
return <div />
}

return <PageRenderer {...this.props} {...data} />
return <PageRenderer {...this.props} {...data.result} />
}
}

Expand Down
10 changes: 3 additions & 7 deletions packages/gatsby/src/utils/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IPageData {
path: IGatsbyPage["path"]
}

interface IPageDataWithQueryResult extends IPageData {
export interface IPageDataWithQueryResult extends IPageData {
result: IExecutionResult
}

Expand Down Expand Up @@ -127,19 +127,15 @@ export async function flush(): Promise<void> {
// them, a page might not exist anymore щ(゚Д゚щ)
// This is why we need this check
if (page) {
const body = await writePageData(
const result = await writePageData(
path.join(program.directory, `public`),
page
)

if (program?._?.[0] === `develop`) {
websocketManager.emitPageData({
...body.result,
id: pagePath,
result: {
data: body.result.data,
pageContext: body.result.pageContext,
},
result,
})
}
}
Expand Down
11 changes: 7 additions & 4 deletions packages/gatsby/src/utils/websocket-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { store } from "../redux"
import { Server as HTTPSServer } from "https"
import { Server as HTTPServer } from "http"
import fs from "fs"
import { readPageData } from "../utils/page-data"
import { readPageData, IPageDataWithQueryResult } from "../utils/page-data"
import telemetry from "gatsby-telemetry"
import url from "url"
import { createHash } from "crypto"
Expand All @@ -13,7 +13,7 @@ import socketIO from "socket.io"

export interface IPageQueryResult {
id: string
result: unknown // TODO: Improve this once we understand what the type is
result?: IPageDataWithQueryResult
}

export interface IStaticQueryResult {
Expand All @@ -35,10 +35,13 @@ const getCachedPageData = async (
const publicDir = path.join(program.directory, `public`)
if (pages.has(denormalizePagePath(pagePath)) || pages.has(pagePath)) {
try {
const pageData = await readPageData(publicDir, pagePath)
const pageData: IPageDataWithQueryResult = await readPageData(
publicDir,
pagePath
)

return {
result: pageData.result,
result: pageData,
id: pagePath,
}
} catch (err) {
Expand Down