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

fix(gatsby): Load static query results from its own Db #26077

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class BaseLoader {
// }
this.pageDb = new Map()
this.inFlightDb = new Map()
this.staticQueryDb = new Map()
this.staticQueryDb = {}
this.pageDataDb = new Map()
this.prefetchTriggered = new Set()
this.prefetchCompleted = new Set()
Expand Down Expand Up @@ -258,8 +258,8 @@ export class BaseLoader {
const staticQueryBatchPromise = Promise.all(
staticQueryHashes.map(staticQueryHash => {
// Check for cache in case this static query result has already been loaded
if (this.staticQueryDb.has(staticQueryHash)) {
const jsonPayload = this.staticQueryDb.get(staticQueryHash)
if (this.staticQueryDb[staticQueryHash]) {
const jsonPayload = this.staticQueryDb[staticQueryHash]
return { staticQueryHash, jsonPayload }
}

Expand All @@ -275,7 +275,7 @@ export class BaseLoader {

staticQueryResults.forEach(({ staticQueryHash, jsonPayload }) => {
staticQueryResultsMap[staticQueryHash] = jsonPayload
this.staticQueryDb.set(staticQueryHash, jsonPayload)
this.staticQueryDb[staticQueryHash] = jsonPayload
})

return staticQueryResultsMap
Expand Down Expand Up @@ -529,6 +529,7 @@ export const publicLoader = {
isPageNotFound: rawPath => instance.isPageNotFound(rawPath),
hovering: rawPath => instance.hovering(rawPath),
loadAppData: () => instance.loadAppData(),
getStaticQueryResults: () => instance.staticQueryDb,
}

export default publicLoader
19 changes: 10 additions & 9 deletions packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ apiRunnerAsync(`onClientEntry`).then(() => {
<Location>
{({ location }) => (
<EnsureResources location={location}>
{({ pageResources, location }) => (
<StaticQueryContext.Provider
value={pageResources.staticQueryResults}
>
<DataContext.Provider value={{ pageResources, location }}>
{children}
</DataContext.Provider>
</StaticQueryContext.Provider>
)}
{({ pageResources, location }) => {
const staticQueryResults = publicLoader.getStaticQueryResults()
return (
<StaticQueryContext.Provider value={staticQueryResults}>
sidharthachatterjee marked this conversation as resolved.
Show resolved Hide resolved
<DataContext.Provider value={{ pageResources, location }}>
{children}
</DataContext.Provider>
</StaticQueryContext.Provider>
)
}}
</EnsureResources>
)}
</Location>
Expand Down