@@ -10,7 +10,6 @@ import {
1010 getScriptsAndStylesForTemplate ,
1111 readWebpackStats ,
1212} from "../client-assets-for-template"
13- import { writeStaticQueryContext } from "../static-query-utils"
1413import { IGatsbyState } from "../../redux/types"
1514import { store } from "../../redux"
1615
@@ -20,27 +19,45 @@ const extensions = [`.mjs`, `.js`, `.json`, `.node`, `.ts`, `.tsx`]
2019const outputDir = path . join ( process . cwd ( ) , `.cache` , `page-ssr` )
2120const cacheLocation = path . join ( process . cwd ( ) , `.cache` , `webpack` , `page-ssr` )
2221
23- export async function writeQueryContext ( {
24- staticQueriesByTemplate ,
22+ export async function copyStaticQueriesToEngine ( {
23+ engineTemplatePaths ,
2524 components,
25+ staticQueriesByTemplate,
2626} : {
27- staticQueriesByTemplate : IGatsbyState [ "staticQueriesByTemplate" ]
27+ engineTemplatePaths : Set < string >
2828 components : IGatsbyState [ "components" ]
29+ staticQueriesByTemplate : IGatsbyState [ "staticQueriesByTemplate" ]
2930} ) : Promise < void > {
30- const waitingForWrites : Array < Promise < unknown > > = [ ]
31- for ( const pageTemplate of components . values ( ) ) {
32- const staticQueryHashes =
33- staticQueriesByTemplate . get ( pageTemplate . componentPath ) || [ ]
31+ const staticQueriesToCopy = new Set < string > ( )
32+
33+ for ( const component of components . values ( ) ) {
34+ // figuring out needed slices for each pages using componentPath is not straightforward
35+ // so for now we just collect static queries for all slices + engine templates
36+ if ( component . isSlice || engineTemplatePaths . has ( component . componentPath ) ) {
37+ const staticQueryHashes =
38+ staticQueriesByTemplate . get ( component . componentPath ) || [ ]
39+
40+ for ( const hash of staticQueryHashes ) {
41+ staticQueriesToCopy . add ( hash )
42+ }
43+ }
44+ }
45+
46+ const sourceDir = path . join ( process . cwd ( ) , `public` , `page-data` , `sq` , `d` )
47+ const destDir = path . join ( outputDir , `sq` )
48+
49+ await fs . ensureDir ( destDir )
50+ await fs . emptyDir ( destDir )
51+
52+ const promisesToAwait : Array < Promise < void > > = [ ]
53+ for ( const hash of staticQueriesToCopy ) {
54+ const sourcePath = path . join ( sourceDir , `${ hash } .json` )
55+ const destPath = path . join ( destDir , `${ hash } .json` )
3456
35- waitingForWrites . push (
36- writeStaticQueryContext (
37- staticQueryHashes ,
38- pageTemplate . componentChunkName
39- )
40- )
57+ promisesToAwait . push ( fs . copy ( sourcePath , destPath ) )
4158 }
4259
43- return Promise . all ( waitingForWrites ) . then ( ( ) => { } )
60+ await Promise . all ( promisesToAwait )
4461}
4562
4663export async function createPageSSRBundle ( {
0 commit comments