Repository: gatsbyjs/gatsby
File: packages/gatsby/cache-dir/loader.js (JavaScript)

Code before:
                `Static query with hash ${staticQueryHash} was fetched`,
                jsonPayload
              )
              // this.staticQueryDb.set(staticQueryHash, jsonPayload)
              return { staticQueryHash, jsonPayload }
            })
          })
        ).then(staticQueryResults => {
          console.log({
            staticQueryResults,
          })
          const staticQueryResultsMap = staticQueryResults.reduce(
            (map, { staticQueryHash, jsonPayload }) => {
              map[staticQueryHash] = jsonPayload
              return map
            },
            {}
          )
          // emitter.emit(`onPostLoadStaticQueryResults`, {
          //   staticQueryResultsMap,
          // })
          this.staticQueryDb.set(pagePath, staticQueryResultsMap)
          return staticQueryResultsMap
        })

        return Promise.all([
          componentChunkPromise,
          staticQueryBatchPromise,
        ]).then(([pageResources, staticQueryResults]) => {
          return {
            ...pageResources,
            staticQueryResults,
          }
        })
      })
      // prefer duplication with then + catch over .finally to prevent problems in ie11 + firefox
      .then(response => {
        this.inFlightDb.delete(pagePath)
        return response
      })
      .catch(err => {
        this.inFlightDb.delete(pagePath)
        throw err
      })

    this.inFlightDb.set(pagePath, inFlight)
    return inFlight
  }

  // returns undefined if loading page ran into errors
  loadPageSync(rawPath) {

Review comment (suggestion):
The double `Promise.all` looks awkward but I have no better suggestion, especially since you also rely on the `.then` receiving the two results separately anyways. :shrug: 

Code after:
              webpackCompilationHash: allData[0]
                ? allData[0].webpackCompilationHash
                : ``,
            })
            pageResources = toPageResources(pageData, component)
          }
          // undefined if final result is an error
          return pageResources
        }
      )

      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)
            return { staticQueryHash, jsonPayload }
          }

          return this.memoizedGet(
            `${__PATH_PREFIX__}/static/d/${staticQueryHash}.json`
          ).then(req => {
            const jsonPayload = JSON.parse(req.responseText)
            return { staticQueryHash, jsonPayload }
          })
        })
      ).then(staticQueryResults => {
        const staticQueryResultsMap = {}

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

        return staticQueryResultsMap
      })

      return Promise.all([componentChunkPromise, staticQueryBatchPromise]).then(
        ([pageResources, staticQueryResults]) => {
          let payload
          if (pageResources) {
            payload = { ...pageResources, staticQueryResults }
            finalResult.payload = payload
            emitter.emit(`onPostLoadPageResources`, {
              page: payload,
              pageResources: payload,
            })
          }

          this.pageDb.set(pagePath, finalResult)