gatsby 2.32.9 → 2.32.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/cache-dir/app.js +2 -3
  3. package/cache-dir/commonjs/app.js +2 -1
  4. package/dist/commands/build.js +5 -1
  5. package/dist/commands/build.js.map +1 -1
  6. package/dist/commands/develop-process.js +5 -1
  7. package/dist/commands/develop-process.js.map +1 -1
  8. package/dist/redux/actions/public.js +16 -6
  9. package/dist/redux/actions/public.js.map +1 -1
  10. package/dist/redux/nodes.js +5 -1
  11. package/dist/redux/nodes.js.map +1 -1
  12. package/dist/redux/reducers/status.d.ts +1 -0
  13. package/dist/redux/reducers/status.js +5 -0
  14. package/dist/redux/reducers/status.js.map +1 -1
  15. package/dist/redux/types.d.ts +1 -0
  16. package/dist/redux/types.js.map +1 -1
  17. package/dist/state-machines/develop/index.js +1 -3
  18. package/dist/state-machines/develop/index.js.map +1 -1
  19. package/dist/utils/dev-ssr/develop-html-route.js +3 -3
  20. package/dist/utils/dev-ssr/develop-html-route.js.map +1 -1
  21. package/dist/utils/dev-ssr/render-dev-html.js +3 -2
  22. package/dist/utils/dev-ssr/render-dev-html.js.map +1 -1
  23. package/dist/utils/develop-preload-headers.js +1 -1
  24. package/dist/utils/develop-preload-headers.js.map +1 -1
  25. package/gatsby-admin-public/4c744e84-6c27fb4a13dc8c8c3e88.js.map +1 -1
  26. package/gatsby-admin-public/69bd6bf3-00a5b50945cce68e041c.js.map +1 -1
  27. package/gatsby-admin-public/784b2cee55c07b638f20445dec340adf9f1888a3-d690a55f56dedc0f95b3.js.map +1 -1
  28. package/gatsby-admin-public/854a7ef1f34af0aefbdfdd9304a0c00251662775-30cef3c004238987a416.js.map +1 -1
  29. package/gatsby-admin-public/{app-ae73c37ae339da42b23e.js → app-749bdcbe1800236c1de3.js} +2 -2
  30. package/gatsby-admin-public/{app-ae73c37ae339da42b23e.js.LICENSE.txt → app-749bdcbe1800236c1de3.js.LICENSE.txt} +0 -0
  31. package/gatsby-admin-public/app-749bdcbe1800236c1de3.js.map +1 -0
  32. package/gatsby-admin-public/c432bec7e9afb3443fd639df9e5f119e13575cf7-976ea4aa8380d4a68cb1.js.map +1 -1
  33. package/gatsby-admin-public/chunk-map.json +1 -1
  34. package/gatsby-admin-public/component---src-pages-index-tsx-70aa31e4e1eca0a560a8.js.map +1 -1
  35. package/gatsby-admin-public/component---src-pages-plugins-tsx-c6700b48ed9ac88a9768.js.map +1 -1
  36. package/gatsby-admin-public/{component---src-pages-recipe-js-48fb05e6af01805f0a27.js → component---src-pages-recipe-js-e508d7ea0c80b0071ca7.js} +1 -1
  37. package/gatsby-admin-public/component---src-pages-recipe-js-e508d7ea0c80b0071ca7.js.map +1 -0
  38. package/gatsby-admin-public/e2852b4470dcb2615e49edcd9de2a3c8119d4bec-fbd253211b90ee4d944c.js.map +1 -1
  39. package/gatsby-admin-public/framework-b5530edc347e85dd3979.js.map +1 -1
  40. package/gatsby-admin-public/index.html +1 -1
  41. package/gatsby-admin-public/page-data/app-data.json +1 -1
  42. package/gatsby-admin-public/pages/index.html +1 -1
  43. package/gatsby-admin-public/plugins/index.html +1 -1
  44. package/gatsby-admin-public/polyfill-dce23570cfd77335f976.js +2 -0
  45. package/gatsby-admin-public/polyfill-dce23570cfd77335f976.js.map +1 -0
  46. package/gatsby-admin-public/recipe/index.html +1 -1
  47. package/gatsby-admin-public/recipes/index.html +1 -1
  48. package/gatsby-admin-public/{webpack-runtime-ece0b6a1fdfb71d1b025.js → webpack-runtime-276364d320252125351e.js} +2 -2
  49. package/gatsby-admin-public/{webpack-runtime-ece0b6a1fdfb71d1b025.js.map → webpack-runtime-276364d320252125351e.js.map} +1 -1
  50. package/gatsby-admin-public/webpack.stats.json +1 -1
  51. package/package.json +7 -7
  52. package/gatsby-admin-public/app-ae73c37ae339da42b23e.js.map +0 -1
  53. package/gatsby-admin-public/component---src-pages-recipe-js-48fb05e6af01805f0a27.js.map +0 -1
  54. package/gatsby-admin-public/polyfill-3220228a1f93ed70393d.js +0 -2
  55. package/gatsby-admin-public/polyfill-3220228a1f93ed70393d.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/state-machines/develop/index.ts"],"names":["RECOMPILE_PANIC_LIMIT","developConfig","id","initial","on","ADD_NODE_MUTATION","actions","SOURCE_FILE_CHANGED","WEBHOOK_RECEIVED","target","QUERY_RUN_REQUESTED","states","initializing","undefined","invoke","src","onDone","onError","initializingData","data","parentSpan","store","webhookBody","deferNodeMutation","runningPostBootstrap","runningQueries","program","gatsbyNodeGraphQLFunction","graphqlRunner","websocketManager","pendingQueryRuns","cond","nodesMutatedDuringQueryRun","nodesMutatedDuringQueryRunRecompileCount","compiler","sourceFilesDirty","recompiling","entry","startingDevServers","waiting","always","size","EXTRACT_QUERIES_NOW","nodeMutationBatch","runningBatch","reloadingData","webhookSourcePluginName","refresh","recreatingPages","developMachine","services","developServices","buildActions"],"mappings":";;;;;AAAA;;AAIA;;AACA;;AAGA,MAAMA,qBAAqB,GAAG,CAA9B;AAEA;AACA;AACA;;AACA,MAAMC,aAAgE,GAAG;AACvEC,EAAAA,EAAE,EAAG,OADkE;AAEvEC,EAAAA,OAAO,EAAG,cAF6D;AAGvE;AACA;AACAC,EAAAA,EAAE,EAAE;AACF;AACAC,IAAAA,iBAAiB,EAAE;AACjBC,MAAAA,OAAO,EAAG;AADO,KAFjB;AAKF;AACAC,IAAAA,mBAAmB,EAAE;AACnBD,MAAAA,OAAO,EAAG;AADS,KANnB;AASF;AACA;AACAE,IAAAA,gBAAgB,EAAE;AAChBC,MAAAA,MAAM,EAAG,eADO;AAEhBH,MAAAA,OAAO,EAAG;AAFM,KAXhB;AAeFI,IAAAA,mBAAmB,EAAE;AACnBJ,MAAAA,OAAO,EAAG;AADS;AAfnB,GALmE;AAwBvEK,EAAAA,MAAM,EAAE;AACN;AACAC,IAAAA,YAAY,EAAE;AACZR,MAAAA,E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A,OAAO,EAAG,qBADJ;AAENG,UAAAA,MAAM,EAAG;AAFH,SANF;AAUNQ,QAAAA,OAAO,EAAE;AACPX,UAAAA,OAAO,EAAG,UADH;AAEPG,UAAAA,MAAM,EAAG;AAFF;AAVH;AAPO;AApRX;AAxB+D,CAAzE;AAsUO,MAAMwC,cAAc,GAAG,qBAAQhD,aAAR,EAAuB;AACnDiD,EAAAA,QAAQ,EAAEC,yBADyC;AAEnD7C,EAAAA,OAAO,EAAE8C;AAF0C,CAAvB,CAAvB","sourcesContent":["import { MachineConfig, AnyEventObject, forwardTo, Machine } from \"xstate\"\nimport { IDataLayerContext } from \"../data-layer/types\"\nimport { IQueryRunningContext } from \"../query-running/types\"\nimport { IWaitingContext } from \"../waiting/types\"\nimport { buildActions } from \"./actions\"\nimport { developServices } from \"./services\"\nimport { IBuildContext } from \"../../services\"\n\nconst RECOMPILE_PANIC_LIMIT = 6\n\n/**\n * This is the top-level state machine for the `gatsby develop` command\n */\nconst developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {\n id: `build`,\n initial: `initializing`,\n // These are mutation events, sent to this machine by the mutation listener\n // in `services/listen-for-mutations.ts`\n on: {\n // These are deferred node mutations, mainly `createNode`\n ADD_NODE_MUTATION: {\n actions: `addNodeMutation`,\n },\n // Sent when webpack or chokidar sees a changed file\n SOURCE_FILE_CHANGED: {\n actions: `markSourceFilesDirty`,\n },\n // These are calls to the refresh endpoint. Also used by Gatsby Preview.\n // Saves the webhook body from the event into context, then reloads data\n WEBHOOK_RECEIVED: {\n target: `reloadingData`,\n actions: `assignWebhookBody`,\n },\n QUERY_RUN_REQUESTED: {\n actions: `trackRequestedQueryRun`,\n },\n },\n states: {\n // Here we handle the initial bootstrap\n initializing: {\n on: {\n // Ignore mutation events because we'll be running everything anyway\n ADD_NODE_MUTATION: undefined,\n SOURCE_FILE_CHANGED: undefined,\n WEBHOOK_RECEIVED: undefined,\n },\n invoke: {\n id: `initialize`,\n src: `initialize`,\n onDone: {\n target: `initializingData`,\n actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`],\n },\n onError: {\n actions: `panic`,\n },\n },\n },\n // Sourcing nodes, customising and inferring schema, then running createPages\n initializingData: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n },\n invoke: {\n id: `initialize-data`,\n src: `initializeData`,\n data: ({\n parentSpan,\n store,\n webhookBody,\n }: IBuildContext): IDataLayerContext => {\n return {\n parentSpan,\n store,\n webhookBody,\n deferNodeMutation: true,\n }\n },\n onDone: {\n actions: [\n `assignServiceResult`,\n `clearWebhookBody`,\n `finishParentSpan`,\n ],\n target: `runningPostBootstrap`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n runningPostBootstrap: {\n invoke: {\n id: `post-bootstrap`,\n src: `postBootstrap`,\n onDone: `runningQueries`,\n },\n },\n // Running page and static queries and generating the SSRed HTML and page data\n runningQueries: {\n on: {\n SOURCE_FILE_CHANGED: {\n actions: [forwardTo(`run-queries`), `markSourceFilesDirty`],\n },\n ADD_NODE_MUTATION: {\n actions: [`markNodesDirty`, `callApi`],\n },\n QUERY_RUN_REQUESTED: {\n actions: forwardTo(`run-queries`),\n },\n },\n invoke: {\n id: `run-queries`,\n src: `runQueries`,\n // This is all the data that we're sending to the child machine\n data: ({\n program,\n store,\n parentSpan,\n gatsbyNodeGraphQLFunction,\n graphqlRunner,\n websocketManager,\n pendingQueryRuns,\n }: IBuildContext): IQueryRunningContext => {\n return {\n program,\n store,\n parentSpan,\n gatsbyNodeGraphQLFunction,\n graphqlRunner,\n websocketManager,\n pendingQueryRuns,\n }\n },\n onDone: [\n {\n // If we're at the recompile limit and nodes were mutated again then panic\n target: `waiting`,\n actions: `panicBecauseOfInfiniteLoop`,\n cond: ({\n nodesMutatedDuringQueryRun = false,\n nodesMutatedDuringQueryRunRecompileCount = 0,\n }: IBuildContext): boolean =>\n nodesMutatedDuringQueryRun &&\n nodesMutatedDuringQueryRunRecompileCount >= RECOMPILE_PANIC_LIMIT,\n },\n {\n // Nodes were mutated while querying, so we need to re-run everything\n target: `recreatingPages`,\n cond: ({ nodesMutatedDuringQueryRun }: IBuildContext): boolean =>\n !!nodesMutatedDuringQueryRun,\n actions: [\n `markNodesClean`,\n `incrementRecompileCount`,\n `clearPendingQueryRuns`,\n ],\n },\n {\n // If we have no compiler (i.e. it's first run), then spin up the\n // webpack and socket.io servers\n target: `startingDevServers`,\n actions: [`setQueryRunningFinished`, `clearPendingQueryRuns`],\n cond: ({ compiler }: IBuildContext): boolean => !compiler,\n },\n {\n // If source files have changed, then recompile the JS bundle\n target: `recompiling`,\n cond: ({ sourceFilesDirty }: IBuildContext): boolean =>\n !!sourceFilesDirty,\n actions: [`clearPendingQueryRuns`],\n },\n {\n // ...otherwise just wait.\n target: `waiting`,\n actions: [`clearPendingQueryRuns`],\n },\n ],\n onError: {\n actions: [`logError`, `clearPendingQueryRuns`],\n target: `waiting`,\n },\n },\n },\n // Recompile the JS bundle\n recompiling: {\n // Important: mark source files as clean when recompiling starts\n // Doing this `onDone` will wipe all file change events that occur **during** recompilation\n // See https://github.com/gatsbyjs/gatsby/issues/27609\n entry: `markSourceFilesClean`,\n invoke: {\n src: `recompile`,\n onDone: {\n target: `waiting`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n // Spin up webpack and socket.io\n startingDevServers: {\n invoke: {\n src: `startWebpackServer`,\n onDone: {\n target: `waiting`,\n actions: [\n `assignServers`,\n `spawnWebpackListener`,\n `markSourceFilesClean`,\n ],\n },\n onError: {\n actions: `panic`,\n target: `waiting`,\n },\n },\n },\n // Idle, waiting for events that make us rebuild\n waiting: {\n always: [\n {\n target: `runningQueries`,\n cond: ({ pendingQueryRuns }: IBuildContext): boolean =>\n !!pendingQueryRuns && pendingQueryRuns.size > 0,\n },\n ],\n entry: [`saveDbState`, `resetRecompileCount`],\n on: {\n // Forward these events to the child machine, so it can handle batching\n ADD_NODE_MUTATION: {\n actions: forwardTo(`waiting`),\n },\n SOURCE_FILE_CHANGED: {\n actions: [forwardTo(`waiting`), `markSourceFilesDirty`],\n },\n // This event is sent from the child\n EXTRACT_QUERIES_NOW: {\n target: `runningQueries`,\n },\n },\n invoke: {\n id: `waiting`,\n src: `waitForMutations`,\n // Send existing queued mutations to the child machine, which will execute them\n data: ({\n store,\n nodeMutationBatch = [],\n sourceFilesDirty,\n }: IBuildContext): IWaitingContext => {\n return {\n store,\n nodeMutationBatch,\n sourceFilesDirty,\n runningBatch: [],\n }\n },\n // \"done\" means we need to rebuild\n onDone: {\n actions: `assignServiceResult`,\n target: `recreatingPages`,\n },\n onError: {\n actions: `panic`,\n },\n },\n },\n // Almost the same as initializing data, but skips various first-run stuff\n reloadingData: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n // Ignore, because we're about to extract them anyway\n SOURCE_FILE_CHANGED: undefined,\n },\n invoke: {\n src: `reloadData`,\n data: ({\n parentSpan,\n store,\n webhookBody,\n webhookSourcePluginName,\n }: IBuildContext): IDataLayerContext => {\n return {\n parentSpan,\n store,\n webhookBody,\n webhookSourcePluginName,\n refresh: true,\n deferNodeMutation: true,\n }\n },\n onDone: {\n actions: [\n `assignServiceResult`,\n `clearWebhookBody`,\n `finishParentSpan`,\n ],\n target: `runningQueries`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n // Rebuild pages if a node has been mutated outside of sourceNodes\n recreatingPages: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n },\n invoke: {\n id: `recreate-pages`,\n src: `recreatePages`,\n data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => {\n return { parentSpan, store, deferNodeMutation: true }\n },\n onDone: {\n actions: `assignServiceResult`,\n target: `runningQueries`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n },\n}\n\nexport const developMachine = Machine(developConfig, {\n services: developServices,\n actions: buildActions,\n})\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/state-machines/develop/index.ts"],"names":["RECOMPILE_PANIC_LIMIT","developConfig","id","initial","on","ADD_NODE_MUTATION","actions","SOURCE_FILE_CHANGED","WEBHOOK_RECEIVED","target","QUERY_RUN_REQUESTED","states","initializing","undefined","invoke","src","onDone","onError","initializingData","data","parentSpan","store","webhookBody","deferNodeMutation","runningPostBootstrap","runningQueries","program","gatsbyNodeGraphQLFunction","graphqlRunner","websocketManager","pendingQueryRuns","cond","nodesMutatedDuringQueryRun","nodesMutatedDuringQueryRunRecompileCount","compiler","sourceFilesDirty","recompiling","entry","startingDevServers","waiting","always","size","EXTRACT_QUERIES_NOW","nodeMutationBatch","runningBatch","reloadingData","webhookSourcePluginName","refresh","recreatingPages","developMachine","services","developServices","buildActions"],"mappings":";;;;;AAAA;;AAIA;;AACA;;AAGA,MAAMA,qBAAqB,GAAG,CAA9B;AAEA;AACA;AACA;;AACA,MAAMC,aAAgE,GAAG;AACvEC,EAAAA,EAAE,EAAG,OADkE;AAEvEC,EAAAA,OAAO,EAAG,cAF6D;AAGvE;AACA;AACAC,EAAAA,EAAE,EAAE;AACF;AACAC,IAAAA,iBAAiB,EAAE;AACjBC,MAAAA,OAAO,EAAG;AADO,KAFjB;AAKF;AACAC,IAAAA,mBAAmB,EAAE;AACnBD,MAAAA,OAAO,EAAG;AADS,KANnB;AASF;AACA;AACAE,IAAAA,gBAAgB,EAAE;AAChBC,MAAAA,MAAM,EAAG,eADO;AAEhBH,MAAAA,OAAO,EAAG;AAFM,KAXhB;AAeFI,IAAAA,mBAAmB,EAAE;AACnBJ,MAAAA,OAAO,EAAG;AADS;AAfnB,GALmE;AAwBvEK,EAAAA,MAAM,EAAE;AACN;AACAC,IAAAA,YAAY,EAAE;AACZR,MAAAA,EAAE,EAAE;AACF;AACAC,QAAAA,iBAAiB,EAAEQ,SAFjB;AAGFN,QAAAA,mBAAmB,EAAEM,SAHnB;AAIFL,QAAAA,gBA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;AAVH;AAPO;AAlRX;AAxB+D,CAAzE;AAoUO,MAAMwC,cAAc,GAAG,qBAAQhD,aAAR,EAAuB;AACnDiD,EAAAA,QAAQ,EAAEC,yBADyC;AAEnD7C,EAAAA,OAAO,EAAE8C;AAF0C,CAAvB,CAAvB","sourcesContent":["import { MachineConfig, AnyEventObject, forwardTo, Machine } from \"xstate\"\nimport { IDataLayerContext } from \"../data-layer/types\"\nimport { IQueryRunningContext } from \"../query-running/types\"\nimport { IWaitingContext } from \"../waiting/types\"\nimport { buildActions } from \"./actions\"\nimport { developServices } from \"./services\"\nimport { IBuildContext } from \"../../services\"\n\nconst RECOMPILE_PANIC_LIMIT = 6\n\n/**\n * This is the top-level state machine for the `gatsby develop` command\n */\nconst developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {\n id: `build`,\n initial: `initializing`,\n // These are mutation events, sent to this machine by the mutation listener\n // in `services/listen-for-mutations.ts`\n on: {\n // These are deferred node mutations, mainly `createNode`\n ADD_NODE_MUTATION: {\n actions: `addNodeMutation`,\n },\n // Sent when webpack or chokidar sees a changed file\n SOURCE_FILE_CHANGED: {\n actions: `markSourceFilesDirty`,\n },\n // These are calls to the refresh endpoint. Also used by Gatsby Preview.\n // Saves the webhook body from the event into context, then reloads data\n WEBHOOK_RECEIVED: {\n target: `reloadingData`,\n actions: `assignWebhookBody`,\n },\n QUERY_RUN_REQUESTED: {\n actions: `trackRequestedQueryRun`,\n },\n },\n states: {\n // Here we handle the initial bootstrap\n initializing: {\n on: {\n // Ignore mutation events because we'll be running everything anyway\n ADD_NODE_MUTATION: undefined,\n SOURCE_FILE_CHANGED: undefined,\n WEBHOOK_RECEIVED: undefined,\n },\n invoke: {\n id: `initialize`,\n src: `initialize`,\n onDone: {\n target: `initializingData`,\n actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`],\n },\n onError: {\n actions: `panic`,\n },\n },\n },\n // Sourcing nodes, customising and inferring schema, then running createPages\n initializingData: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n },\n invoke: {\n id: `initialize-data`,\n src: `initializeData`,\n data: ({\n parentSpan,\n store,\n webhookBody,\n }: IBuildContext): IDataLayerContext => {\n return {\n parentSpan,\n store,\n webhookBody,\n deferNodeMutation: true,\n }\n },\n onDone: {\n actions: [\n `assignServiceResult`,\n `clearWebhookBody`,\n `finishParentSpan`,\n ],\n target: `runningPostBootstrap`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n runningPostBootstrap: {\n invoke: {\n id: `post-bootstrap`,\n src: `postBootstrap`,\n onDone: `runningQueries`,\n },\n },\n // Running page and static queries and generating the SSRed HTML and page data\n runningQueries: {\n on: {\n SOURCE_FILE_CHANGED: {\n actions: [forwardTo(`run-queries`), `markSourceFilesDirty`],\n },\n ADD_NODE_MUTATION: {\n actions: [`markNodesDirty`, `callApi`],\n },\n QUERY_RUN_REQUESTED: {\n actions: forwardTo(`run-queries`),\n },\n },\n invoke: {\n id: `run-queries`,\n src: `runQueries`,\n // This is all the data that we're sending to the child machine\n data: ({\n program,\n store,\n parentSpan,\n gatsbyNodeGraphQLFunction,\n graphqlRunner,\n websocketManager,\n pendingQueryRuns,\n }: IBuildContext): IQueryRunningContext => {\n return {\n program,\n store,\n parentSpan,\n gatsbyNodeGraphQLFunction,\n graphqlRunner,\n websocketManager,\n pendingQueryRuns,\n }\n },\n onDone: [\n {\n // If we're at the recompile limit and nodes were mutated again then panic\n target: `waiting`,\n actions: `panicBecauseOfInfiniteLoop`,\n cond: ({\n nodesMutatedDuringQueryRun = false,\n nodesMutatedDuringQueryRunRecompileCount = 0,\n }: IBuildContext): boolean =>\n nodesMutatedDuringQueryRun &&\n nodesMutatedDuringQueryRunRecompileCount >= RECOMPILE_PANIC_LIMIT,\n },\n {\n // Nodes were mutated while querying, so we need to re-run everything\n target: `recreatingPages`,\n cond: ({ nodesMutatedDuringQueryRun }: IBuildContext): boolean =>\n !!nodesMutatedDuringQueryRun,\n actions: [\n `markNodesClean`,\n `incrementRecompileCount`,\n `clearPendingQueryRuns`,\n ],\n },\n {\n // If we have no compiler (i.e. it's first run), then spin up the\n // webpack and socket.io servers\n target: `startingDevServers`,\n actions: [`setQueryRunningFinished`, `clearPendingQueryRuns`],\n cond: ({ compiler }: IBuildContext): boolean => !compiler,\n },\n {\n // If source files have changed, then recompile the JS bundle\n target: `recompiling`,\n cond: ({ sourceFilesDirty }: IBuildContext): boolean =>\n !!sourceFilesDirty,\n actions: [`clearPendingQueryRuns`],\n },\n {\n // ...otherwise just wait.\n target: `waiting`,\n actions: [`clearPendingQueryRuns`],\n },\n ],\n onError: {\n actions: [`logError`, `clearPendingQueryRuns`],\n target: `waiting`,\n },\n },\n },\n // Recompile the JS bundle\n recompiling: {\n // Important: mark source files as clean when recompiling starts\n // Doing this `onDone` will wipe all file change events that occur **during** recompilation\n // See https://github.com/gatsbyjs/gatsby/issues/27609\n entry: `markSourceFilesClean`,\n invoke: {\n src: `recompile`,\n onDone: {\n target: `waiting`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n // Spin up webpack and socket.io\n startingDevServers: {\n invoke: {\n src: `startWebpackServer`,\n onDone: {\n target: `waiting`,\n actions: [\n `assignServers`,\n `spawnWebpackListener`,\n `markSourceFilesClean`,\n ],\n },\n onError: {\n actions: `panic`,\n target: `waiting`,\n },\n },\n },\n // Idle, waiting for events that make us rebuild\n waiting: {\n always: [\n {\n target: `runningQueries`,\n cond: ({ pendingQueryRuns }: IBuildContext): boolean =>\n !!pendingQueryRuns && pendingQueryRuns.size > 0,\n },\n ],\n entry: [`saveDbState`, `resetRecompileCount`],\n on: {\n // Forward these events to the child machine, so it can handle batching\n ADD_NODE_MUTATION: {\n actions: forwardTo(`waiting`),\n },\n SOURCE_FILE_CHANGED: {\n actions: [forwardTo(`waiting`), `markSourceFilesDirty`],\n },\n // This event is sent from the child\n EXTRACT_QUERIES_NOW: {\n target: `runningQueries`,\n },\n },\n invoke: {\n id: `waiting`,\n src: `waitForMutations`,\n // Send existing queued mutations to the child machine, which will execute them\n data: ({\n store,\n nodeMutationBatch = [],\n sourceFilesDirty,\n }: IBuildContext): IWaitingContext => {\n return {\n store,\n nodeMutationBatch,\n sourceFilesDirty,\n runningBatch: [],\n }\n },\n // \"done\" means we need to rebuild\n onDone: {\n actions: `assignServiceResult`,\n target: `recreatingPages`,\n },\n onError: {\n actions: `panic`,\n },\n },\n },\n // Almost the same as initializing data, but skips various first-run stuff\n reloadingData: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n },\n invoke: {\n src: `reloadData`,\n data: ({\n parentSpan,\n store,\n webhookBody,\n webhookSourcePluginName,\n }: IBuildContext): IDataLayerContext => {\n return {\n parentSpan,\n store,\n webhookBody,\n webhookSourcePluginName,\n refresh: true,\n deferNodeMutation: true,\n }\n },\n onDone: {\n actions: [\n `assignServiceResult`,\n `clearWebhookBody`,\n `finishParentSpan`,\n ],\n target: `runningQueries`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n // Rebuild pages if a node has been mutated outside of sourceNodes\n recreatingPages: {\n on: {\n // We need to run mutations immediately when in this state\n ADD_NODE_MUTATION: {\n actions: `callApi`,\n },\n },\n invoke: {\n id: `recreate-pages`,\n src: `recreatePages`,\n data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => {\n return { parentSpan, store, deferNodeMutation: true }\n },\n onDone: {\n actions: `assignServiceResult`,\n target: `runningQueries`,\n },\n onError: {\n actions: `logError`,\n target: `waiting`,\n },\n },\n },\n },\n}\n\nexport const developMachine = Machine(developConfig, {\n services: developServices,\n actions: buildActions,\n})\n"],"file":"index.js"}
@@ -22,13 +22,13 @@ const route = ({
22
22
  }) => // Render an HTML page and serve it.
23
23
  app.get(`*`, async (req, res, next) => {
24
24
  (0, _gatsbyTelemetry.trackFeatureIsUsed)(`GATSBY_EXPERIMENTAL_DEV_SSR`);
25
- const pathObj = (0, _findPageByPath.findPageByPath)(store.getState(), req.path);
25
+ const pathObj = (0, _findPageByPath.findPageByPath)(store.getState(), decodeURI(req.path));
26
26
 
27
27
  if (!pathObj) {
28
28
  return next();
29
29
  }
30
30
 
31
- await (0, _developPreloadHeaders.appendPreloadHeaders)(req.path, res);
31
+ await (0, _developPreloadHeaders.appendPreloadHeaders)(pathObj.path, res);
32
32
 
33
33
  const htmlActivity = _reporter.default.phantomActivity(`building HTML for path`, {});
34
34
 
@@ -166,7 +166,7 @@ app.get(`*`, async (req, res, next) => {
166
166
  node.js, it errored.
167
167
  </p>
168
168
  <ul>
169
- <li><strong>URL path:</strong> <code>${req.path}</code></li>
169
+ <li><strong>URL path:</strong> <code>${pathObj.path}</code></li>
170
170
  <li><strong>File path:</strong> <code>${error.filename}</code></li>
171
171
  </ul>
172
172
  <h3>error</h3>
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/dev-ssr/develop-html-route.ts"],"names":["route","app","program","store","get","req","res","next","pathObj","getState","path","htmlActivity","report","phantomActivity","start","renderResponse","page","skipSsr","query","htmlComponentRendererPath","directory","status","send","error","id","filePath","filename","location","line","column","row","context","errorHtml","message","codeFrame","end"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AAEO,MAAMA,KAAK,GAAG,CAAC;AAAEC,EAAAA,GAAF;AAAOC,EAAAA,OAAP;AAAgBC,EAAAA;AAAhB,CAAD,KACnB;AACAF,GAAG,CAACG,GAAJ,CAAS,GAAT,EAAa,OAAOC,GAAP,EAAYC,GAAZ,EAAiBC,IAAjB,KAA0B;AACrC,2CAAoB,6BAApB;AAEA,QAAMC,OAAO,GAAG,oCAAeL,KAAK,CAACM,QAAN,EAAf,EAAiCJ,GAAG,CAACK,IAArC,CAAhB;;AAEA,MAAI,CAACF,OAAL,EAAc;AACZ,WAAOD,IAAI,EAAX;AACD;;AAED,QAAM,iDAAqBF,GAAG,CAACK,IAAzB,EAA+BJ,GAA/B,CAAN;;AAEA,QAA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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAiD3B,GAAG,CAACK,IAAK;AAC1D,kDAAkDa,KAAK,CAACG,QAAS;AACjE;AACA;AACA,6EAA6EH,KAAK,CAACU,OAAQ;AAC3F,SAtGM;;AAwGA,QAAIV,KAAK,CAACW,SAAV,EAAqB;AACnBF,MAAAA,SAAS,IAAK,QAAOT,KAAK,CAACW,SAAU,QAArC;AACD,KAlIa,CAoId;;;AACAF,IAAAA,SAAS,IAAK;AACpB;AACA,+HAFM,CArIc,CAyId;;AACAA,IAAAA,SAAS,IAAK;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAnBM;AAoBA1B,IAAAA,GAAG,CAACe,MAAJ,CAAW,GAAX,EAAgBC,IAAhB,CAAqBU,SAArB;AACD;;AAEDrB,EAAAA,YAAY,CAACwB,GAAb,GAzLqC,CA2LrC;;AACA,SAAO,IAAP;AACD,CA7LD,CAFK","sourcesContent":["import report from \"gatsby-cli/lib/reporter\"\nimport { trackFeatureIsUsed } from \"gatsby-telemetry\"\n\nimport { findPageByPath } from \"../find-page-by-path\"\nimport { renderDevHTML } from \"./render-dev-html\"\nimport { appendPreloadHeaders } from \"../develop-preload-headers\"\n\nexport const route = ({ app, program, store }): any =>\n // Render an HTML page and serve it.\n app.get(`*`, async (req, res, next) => {\n trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`)\n\n const pathObj = findPageByPath(store.getState(), req.path)\n\n if (!pathObj) {\n return next()\n }\n\n await appendPreloadHeaders(req.path, res)\n\n const htmlActivity = report.phantomActivity(`building HTML for path`, {})\n htmlActivity.start()\n\n try {\n const renderResponse = await renderDevHTML({\n path: pathObj.path,\n page: pathObj,\n skipSsr: req.query[`skip-ssr`] || false,\n store,\n htmlComponentRendererPath: `${program.directory}/public/render-page.js`,\n directory: program.directory,\n })\n res.status(200).send(renderResponse)\n } catch (error) {\n // THe page errored but couldn't read the page component.\n // This is a race condition when a page is deleted but its requested\n // immediately after before anything can recompile.\n if (error === `404 page`) {\n return next()\n }\n\n report.error({\n id: `11614`,\n filePath: error.filename,\n location: {\n start: {\n line: error.line,\n column: error.row,\n },\n },\n context: {\n path: pathObj.path,\n filePath: error.filename,\n line: error.line,\n column: error.row,\n },\n })\n let errorHtml = `<head>\n <title>Develop SSR Error</title>\n <style>\n * {\n --gatsby: #663399;\n --gatsbyLight: #9158ca;\n --dimmedWhite: rgba(255, 255, 255, 0.8);\n --white: #ffffff;\n --black: #000000;\n --color-ansi-selection: rgba(95, 126, 151, 0.48);\n --color-ansi-bg: #fafafa;\n --color-ansi-fg: #545454;\n --color-ansi-white: #969896;\n --color-ansi-black: #141414;\n --color-ansi-blue: #183691;\n --color-ansi-cyan: #007faa;\n --color-ansi-green: #008000;\n --color-ansi-magenta: #795da3;\n --color-ansi-red: #d91e18;\n --color-ansi-yellow: #aa5d00;\n --color-ansi-bright-white: #ffffff;\n --color-ansi-bright-black: #545454;\n --color-ansi-bright-blue: #183691;\n --color-ansi-bright-cyan: #007faa;\n --color-ansi-bright-green: #008000;\n --color-ansi-bright-magenta: #795da3;\n --color-ansi-bright-red: #d91e18;\n --color-ansi-bright-yellow: #aa5d00;\n --radii: 5px;\n --z-index-normal: 5;\n --z-index-elevated: 10;\n --space: 1.5em;\n --space-sm: 1em;\n --space-lg: 2.5em;\n }\n [data-gatsby-overlay=\"backdrop\"] {\n background: rgba(72, 67, 79, 0.5);\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n height: 100%;\n width: 100%;\n z-index: var(--z-index-normal);\n backdrop-filter: blur(10px);\n }\n body {\n font: 18px/1.5 -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto,\n Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\",\n \"Segoe UI Symbol\" !important;\n background: var(--color-ansi-bright-white);\n padding: var(--space);\n overflow: auto;\n }\n h1,\n h2,\n h3 {\n display: flex;\n align-items: center;\n color: var(--dimmedWhite);\n background: var(--gatsby);\n padding: var(--space);\n border-top-left-radius: var(--radii);\n border-top-right-radius: var(--radii);\n }\n code {\n font-family: Consolas, \"Andale Mono WT\", \"Andale Mono\", \"Lucida Console\", \"Lucida Sans Typewriter\", \"DejaVu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Liberation Mono\", \"Nimbus Mono L\", Monaco, \"Courier New\", Courier, monospace;\n }\n pre {\n margin: 0;\n color: var(--color-ansi-fg);\n padding: var(--space-sm);\n border-radius: var(--radii);\n }\n button {\n cursor: pointer;\n border: 1px;\n padding: 10px;\n background-color: var(--gatsbyLight);\n color: var(--white);\n appearance: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: var(--radii);\n }\n </style>\n </head>\n <h1>Error</h1>\n <h2>The page didn't server render (SSR) correctly</h2>\n <p style=\"padding-left: var(--space-sm);\">\n React components in Gatsby must render successfully in the browser and in a\n node.js environment. When we tried to render your page component in\n node.js, it errored.\n </p>\n <ul>\n <li><strong>URL path:</strong> <code>${req.path}</code></li>\n <li><strong>File path:</strong> <code>${error.filename}</code></li>\n </ul>\n <h3>error</h3>\n <code style=\"padding: var(--space);padding-left: var(--space-sm);\">${error.message}</code>\n `\n\n if (error.codeFrame) {\n errorHtml += `<pre>${error.codeFrame}</pre>`\n }\n\n // Add link to help page\n errorHtml += `\n <p>For help debugging SSR errors, see this docs page: <a\n href=\"https://www.gatsbyjs.com/docs/debugging-html-builds/\">https://www.gatsbyjs.com/docs/debugging-html-builds/</a></p>`\n\n // Add skip ssr button\n errorHtml += `\n <h3>Skip SSR</h3>\n <p style=\"padding-left: var(--space-sm);\">\n If you don't wish to fix the SSR error at the moment, press the\n button below to reload the page without attempting SSR</p>\n <p style=\"padding-left: var(--space-sm);\">\n <strong>Note</strong>: this error will show up in when you build your site so must be fixed before then.</p>\n <p style=\"padding-left: var(--space-sm);\">\n <strong>Caveat</strong>: SSR errors in module scope i.e. outside of your components can't be skipped so will need fixed before you can continue</p>\n <button style=\"margin-left: var(--space-sm);\" onclick='refreshWithQueryString()'>Skip SSR</button>\n <script>\n function refreshWithQueryString() {\n if ('URLSearchParams' in window) {\n var searchParams = new URLSearchParams(window.location.search);\n searchParams.set(\"skip-ssr\", \"true\");\n window.location.search = searchParams.toString();\n }\n }\n </script>\n `\n res.status(500).send(errorHtml)\n }\n\n htmlActivity.end()\n\n // Make eslint happy\n return null\n })\n"],"file":"develop-html-route.js"}
1
+ {"version":3,"sources":["../../../src/utils/dev-ssr/develop-html-route.ts"],"names":["route","app","program","store","get","req","res","next","pathObj","getState","decodeURI","path","htmlActivity","report","phantomActivity","start","renderResponse","page","skipSsr","query","htmlComponentRendererPath","directory","status","send","error","id","filePath","filename","location","line","column","row","context","errorHtml","message","codeFrame","end"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AAEO,MAAMA,KAAK,GAAG,CAAC;AAAEC,EAAAA,GAAF;AAAOC,EAAAA,OAAP;AAAgBC,EAAAA;AAAhB,CAAD,KACnB;AACAF,GAAG,CAACG,GAAJ,CAAS,GAAT,EAAa,OAAOC,GAAP,EAAYC,GAAZ,EAAiBC,IAAjB,KAA0B;AACrC,2CAAoB,6BAApB;AAEA,QAAMC,OAAO,GAAG,oCAAeL,KAAK,CAACM,QAAN,EAAf,EAAiCC,SAAS,CAACL,GAAG,CAACM,IAAL,CAA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MAAM,EAAEN,KAAK,CAACO;AAJP;AATE,KAAb;;AAgBA,QAAIE,SAAS,GAAI;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAiDzB,OAAO,CAACG,IAAK;AAC9D,kDAAkDa,KAAK,CAACG,QAAS;AACjE;AACA;AACA,6EAA6EH,KAAK,CAACU,OAAQ;AAC3F,SAtGM;;AAwGA,QAAIV,KAAK,CAACW,SAAV,EAAqB;AACnBF,MAAAA,SAAS,IAAK,QAAOT,KAAK,CAACW,SAAU,QAArC;AACD,KAlIa,CAoId;;;AACAF,IAAAA,SAAS,IAAK;AACpB;AACA,+HAFM,CArIc,CAyId;;AACAA,IAAAA,SAAS,IAAK;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAnBM;AAoBA3B,IAAAA,GAAG,CAACgB,MAAJ,CAAW,GAAX,EAAgBC,IAAhB,CAAqBU,SAArB;AACD;;AAEDrB,EAAAA,YAAY,CAACwB,GAAb,GAzLqC,CA2LrC;;AACA,SAAO,IAAP;AACD,CA7LD,CAFK","sourcesContent":["import report from \"gatsby-cli/lib/reporter\"\nimport { trackFeatureIsUsed } from \"gatsby-telemetry\"\n\nimport { findPageByPath } from \"../find-page-by-path\"\nimport { renderDevHTML } from \"./render-dev-html\"\nimport { appendPreloadHeaders } from \"../develop-preload-headers\"\n\nexport const route = ({ app, program, store }): any =>\n // Render an HTML page and serve it.\n app.get(`*`, async (req, res, next) => {\n trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`)\n\n const pathObj = findPageByPath(store.getState(), decodeURI(req.path))\n\n if (!pathObj) {\n return next()\n }\n\n await appendPreloadHeaders(pathObj.path, res)\n\n const htmlActivity = report.phantomActivity(`building HTML for path`, {})\n htmlActivity.start()\n\n try {\n const renderResponse = await renderDevHTML({\n path: pathObj.path,\n page: pathObj,\n skipSsr: req.query[`skip-ssr`] || false,\n store,\n htmlComponentRendererPath: `${program.directory}/public/render-page.js`,\n directory: program.directory,\n })\n res.status(200).send(renderResponse)\n } catch (error) {\n // THe page errored but couldn't read the page component.\n // This is a race condition when a page is deleted but its requested\n // immediately after before anything can recompile.\n if (error === `404 page`) {\n return next()\n }\n\n report.error({\n id: `11614`,\n filePath: error.filename,\n location: {\n start: {\n line: error.line,\n column: error.row,\n },\n },\n context: {\n path: pathObj.path,\n filePath: error.filename,\n line: error.line,\n column: error.row,\n },\n })\n let errorHtml = `<head>\n <title>Develop SSR Error</title>\n <style>\n * {\n --gatsby: #663399;\n --gatsbyLight: #9158ca;\n --dimmedWhite: rgba(255, 255, 255, 0.8);\n --white: #ffffff;\n --black: #000000;\n --color-ansi-selection: rgba(95, 126, 151, 0.48);\n --color-ansi-bg: #fafafa;\n --color-ansi-fg: #545454;\n --color-ansi-white: #969896;\n --color-ansi-black: #141414;\n --color-ansi-blue: #183691;\n --color-ansi-cyan: #007faa;\n --color-ansi-green: #008000;\n --color-ansi-magenta: #795da3;\n --color-ansi-red: #d91e18;\n --color-ansi-yellow: #aa5d00;\n --color-ansi-bright-white: #ffffff;\n --color-ansi-bright-black: #545454;\n --color-ansi-bright-blue: #183691;\n --color-ansi-bright-cyan: #007faa;\n --color-ansi-bright-green: #008000;\n --color-ansi-bright-magenta: #795da3;\n --color-ansi-bright-red: #d91e18;\n --color-ansi-bright-yellow: #aa5d00;\n --radii: 5px;\n --z-index-normal: 5;\n --z-index-elevated: 10;\n --space: 1.5em;\n --space-sm: 1em;\n --space-lg: 2.5em;\n }\n [data-gatsby-overlay=\"backdrop\"] {\n background: rgba(72, 67, 79, 0.5);\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n height: 100%;\n width: 100%;\n z-index: var(--z-index-normal);\n backdrop-filter: blur(10px);\n }\n body {\n font: 18px/1.5 -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto,\n Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\",\n \"Segoe UI Symbol\" !important;\n background: var(--color-ansi-bright-white);\n padding: var(--space);\n overflow: auto;\n }\n h1,\n h2,\n h3 {\n display: flex;\n align-items: center;\n color: var(--dimmedWhite);\n background: var(--gatsby);\n padding: var(--space);\n border-top-left-radius: var(--radii);\n border-top-right-radius: var(--radii);\n }\n code {\n font-family: Consolas, \"Andale Mono WT\", \"Andale Mono\", \"Lucida Console\", \"Lucida Sans Typewriter\", \"DejaVu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Liberation Mono\", \"Nimbus Mono L\", Monaco, \"Courier New\", Courier, monospace;\n }\n pre {\n margin: 0;\n color: var(--color-ansi-fg);\n padding: var(--space-sm);\n border-radius: var(--radii);\n }\n button {\n cursor: pointer;\n border: 1px;\n padding: 10px;\n background-color: var(--gatsbyLight);\n color: var(--white);\n appearance: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: var(--radii);\n }\n </style>\n </head>\n <h1>Error</h1>\n <h2>The page didn't server render (SSR) correctly</h2>\n <p style=\"padding-left: var(--space-sm);\">\n React components in Gatsby must render successfully in the browser and in a\n node.js environment. When we tried to render your page component in\n node.js, it errored.\n </p>\n <ul>\n <li><strong>URL path:</strong> <code>${pathObj.path}</code></li>\n <li><strong>File path:</strong> <code>${error.filename}</code></li>\n </ul>\n <h3>error</h3>\n <code style=\"padding: var(--space);padding-left: var(--space-sm);\">${error.message}</code>\n `\n\n if (error.codeFrame) {\n errorHtml += `<pre>${error.codeFrame}</pre>`\n }\n\n // Add link to help page\n errorHtml += `\n <p>For help debugging SSR errors, see this docs page: <a\n href=\"https://www.gatsbyjs.com/docs/debugging-html-builds/\">https://www.gatsbyjs.com/docs/debugging-html-builds/</a></p>`\n\n // Add skip ssr button\n errorHtml += `\n <h3>Skip SSR</h3>\n <p style=\"padding-left: var(--space-sm);\">\n If you don't wish to fix the SSR error at the moment, press the\n button below to reload the page without attempting SSR</p>\n <p style=\"padding-left: var(--space-sm);\">\n <strong>Note</strong>: this error will show up in when you build your site so must be fixed before then.</p>\n <p style=\"padding-left: var(--space-sm);\">\n <strong>Caveat</strong>: SSR errors in module scope i.e. outside of your components can't be skipped so will need fixed before you can continue</p>\n <button style=\"margin-left: var(--space-sm);\" onclick='refreshWithQueryString()'>Skip SSR</button>\n <script>\n function refreshWithQueryString() {\n if ('URLSearchParams' in window) {\n var searchParams = new URLSearchParams(window.location.search);\n searchParams.set(\"skip-ssr\", \"true\");\n window.location.search = searchParams.toString();\n }\n }\n </script>\n `\n res.status(500).send(errorHtml)\n }\n\n htmlActivity.end()\n\n // Make eslint happy\n return null\n })\n"],"file":"develop-html-route.js"}
@@ -72,8 +72,9 @@ const restartWorker = htmlComponentRendererPath => {
72
72
  exports.restartWorker = restartWorker;
73
73
 
74
74
  const searchFileForString = (substring, filePath) => new Promise(resolve => {
75
- // See if the chunk is in the newComponents array (not the notVisited).
76
- const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`);
75
+ const escapedSubString = substring.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`); // See if the chunk is in the newComponents array (not the notVisited).
76
+
77
+ const chunkRegex = RegExp(`exports.ssrComponents.*${escapedSubString}.*}`, `gs`);
77
78
 
78
79
  const stream = _fsExtra.default.createReadStream(filePath);
79
80
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/dev-ssr/render-dev-html.ts"],"names":["startWorker","newWorker","JestWorker","require","resolve","exposedMethods","numWorkers","forkOptions","silent","env","process","NODE_ENV","forceColors","GATSBY_EXPERIMENTAL_DEV_SSR","warmup","worker","initDevWorkerPool","changeCount","restartWorker","htmlComponentRendererPath","oldWorker","end","deleteModuleCache","searchFileForString","substring","filePath","Promise","chunkRegex","RegExp","stream","fs","createReadStream","found","on","d","test","toString","close","ensurePathComponentInSSRBundle","page","directory","report","panic","componentChunkName","readAttempts","searchForStringInterval","setInterval","clearInterval","renderDevHTML","path","skipSsr","store","reject","pageObj","getState","isClientOnlyPage","matchPath","boundActionCreators","createServerVisitedPage","devssrWebpackCompiler","devssrWebpackWatcher","needToRecompileSSRBundle","isResolved","finish","stats","emitter","off","resume","suspend","setTimeout","htmlString","renderHTML","componentPath","component","error"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,WAAW,GAAG,MAAW;AAC7B,QAAMC,SAAS,GAAG,IAAIC,mBAAJ,CAAeC,OAAO,CAACC,OAAR,CAAiB,yBAAjB,CAAf,EAA2D;AAC3EC,IAAAA,cAAc,EAAE,CAAE,YAAF,EAAgB,mBAAhB,EAAqC,QAArC,CAD2D;AAE3EC,IAAAA,UAAU,EAAE,CAF+D;AAG3EC,IAAAA,WAAW,EAAE;AACXC,MAAAA,MAAM,EAAE,KADG;AAEXC,MAAAA,GAAG,EAAE,EACH,GAAGC,OAAO,CAACD,GADR;AAEHE,QAAAA,QAAQ,EAAE,+BAAU,YAAV,GAAyB,aAFhC;AAGHC,QAAAA,WAAW,EAAE,IAHV;AAIHC,QAAAA,2BAA2B,EAAE;AAJ1B;AAFM;AAH8D,GAA3D,CAAlB,CAD6B,CAe7B;AACA;AACA;;AACAZ,EAAAA,SAAS,CAACa,MAAV;AAEA,SAAOb,SAAP;AACD,CArBD;;AAuBA,IAAIc,MAAJ;;AAC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AACfP,QAAAA,UAAU,GAAG,IAAb;AACA1D,QAAAA,OAAO;AACR,OAHS,EAGP,IAHO,CAAV;AAID,KAjBK,CAAN;AAkBD,GA9DoC,CAgErC;;;AACA,QAAM4B,KAAK,GAAG,MAAMM,8BAA8B,CAACe,OAAD,EAAUb,SAAV,CAAlD,CAjEqC,CAmErC;AACA;AACA;AACA;AACA;AACA;;AACA,MAAI,CAACR,KAAL,EAAY;AACVuB,IAAAA,gBAAgB,GAAG,IAAnB;AACD,GA3EoC,CA6ErC;;;AACA,MAAIL,OAAJ,EAAa;AACXK,IAAAA,gBAAgB,GAAG,IAAnB;AACD;;AAED,MAAI;AACF,UAAMe,UAAU,GAAG,MAAMvD,MAAM,CAACwD,UAAP,CAAkB;AACzCtB,MAAAA,IADyC;AAEzCuB,MAAAA,aAAa,EAAEnB,OAAO,CAACoB,SAFkB;AAGzCtD,MAAAA,yBAHyC;AAIzCqB,MAAAA,SAJyC;AAKzCe,MAAAA;AALyC,KAAlB,CAAzB;AAOA,WAAOnD,OAAO,CAACkE,UAAD,CAAd;AACD,GATD,CASE,OAAOI,KAAP,EAAc;AACd,WAAOtB,MAAM,CAACsB,KAAD,CAAb;AACD;AACF,CA9FD,CARK","sourcesContent":["import JestWorker from \"jest-worker\"\nimport fs from \"fs-extra\"\nimport { joinPath } from \"gatsby-core-utils\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport { isCI } from \"gatsby-core-utils\"\n\nimport { startListener } from \"../../bootstrap/requires-writer\"\nimport { findPageByPath } from \"../find-page-by-path\"\nimport { getPageData as getPageDataExperimental } from \"../get-page-data\"\nimport { getDevSSRWebpack } from \"../../commands/build-html\"\nimport { emitter } from \"../../redux\"\n\nconst startWorker = (): any => {\n const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), {\n exposedMethods: [`renderHTML`, `deleteModuleCache`, `warmup`],\n numWorkers: 1,\n forkOptions: {\n silent: false,\n env: {\n ...process.env,\n NODE_ENV: isCI() ? `production` : `development`,\n forceColors: true,\n GATSBY_EXPERIMENTAL_DEV_SSR: true,\n },\n },\n })\n\n // jest-worker is lazy with forking but we want to fork immediately so the user\n // doesn't have to wait.\n // @ts-ignore\n newWorker.warmup()\n\n return newWorker\n}\n\nlet worker\nexport const initDevWorkerPool = (): void => {\n worker = startWorker()\n}\n\nlet changeCount = 0\nexport const restartWorker = (htmlComponentRendererPath): void => {\n changeCount += 1\n // Forking is expensive — each time we re-require the outputted webpack\n // file, memory grows ~10 mb — 25 regenerations means ~250mb which seems\n // like an accepatable amount of memory to grow before we reclaim it\n // by rebooting the worker process.\n if (changeCount > 25) {\n const oldWorker = worker\n const newWorker = startWorker()\n worker = newWorker\n oldWorker.end()\n changeCount = 0\n } else {\n worker.deleteModuleCache(htmlComponentRendererPath)\n }\n}\n\nconst searchFileForString = (substring, filePath): Promise<boolean> =>\n new Promise(resolve => {\n // See if the chunk is in the newComponents array (not the notVisited).\n const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`)\n const stream = fs.createReadStream(filePath)\n let found = false\n stream.on(`data`, function (d) {\n if (chunkRegex.test(d.toString())) {\n found = true\n stream.close()\n resolve(found)\n }\n })\n stream.on(`error`, function () {\n resolve(found)\n })\n stream.on(`close`, function () {\n resolve(found)\n })\n })\n\nconst ensurePathComponentInSSRBundle = async (\n page,\n directory\n): Promise<any> => {\n // This shouldn't happen.\n if (!page) {\n report.panic(`page not found`, page)\n }\n\n // Now check if it's written to public/render-page.js\n const htmlComponentRendererPath = joinPath(directory, `public/render-page.js`)\n // This search takes 1-10ms\n // We do it as there can be a race conditions where two pages\n // are requested at the same time which means that both are told render-page.js\n // has changed when the first page is complete meaning the second\n // page's component won't be in the render meaning its SSR will fail.\n let found = await searchFileForString(\n page.componentChunkName,\n htmlComponentRendererPath\n )\n\n if (!found) {\n await new Promise(resolve => {\n let readAttempts = 0\n const searchForStringInterval = setInterval(async () => {\n readAttempts += 1\n found = await searchFileForString(\n page.componentChunkName,\n htmlComponentRendererPath\n )\n if (found || readAttempts > 5) {\n clearInterval(searchForStringInterval)\n resolve()\n }\n }, 300)\n })\n }\n\n return found\n}\n\nexport const renderDevHTML = ({\n path,\n page,\n skipSsr = false,\n store,\n htmlComponentRendererPath,\n directory,\n}): Promise<string> =>\n new Promise(async (resolve, reject) => {\n startListener()\n let pageObj\n if (!page) {\n pageObj = findPageByPath(store.getState(), path)\n } else {\n pageObj = page\n }\n\n let isClientOnlyPage = false\n if (pageObj.matchPath) {\n isClientOnlyPage = true\n }\n\n const { boundActionCreators } = require(`../../redux/actions`)\n const { createServerVisitedPage } = boundActionCreators\n // Record this page was requested. This will kick off adding its page\n // component to the ssr bundle (if that's not already happened)\n createServerVisitedPage(pageObj.componentChunkName)\n\n // Ensure the query has been run and written out.\n try {\n await getPageDataExperimental(pageObj.path)\n } catch {\n // If we can't get the page, it was probably deleted recently\n // so let's just do a 404 page.\n return reject(`404 page`)\n }\n\n // Resume the webpack watcher and wait for any compilation necessary to happen.\n // We timeout after 1.5s as the user might not care per se about SSR.\n //\n // We pause and resume so there's no excess webpack activity during normal development.\n const {\n devssrWebpackCompiler,\n devssrWebpackWatcher,\n needToRecompileSSRBundle,\n } = getDevSSRWebpack()\n if (\n devssrWebpackWatcher &&\n devssrWebpackCompiler &&\n needToRecompileSSRBundle\n ) {\n let isResolved = false\n await new Promise(resolve => {\n function finish(stats: Stats): void {\n emitter.off(`DEV_SSR_COMPILATION_DONE`, finish)\n if (!isResolved) {\n resolve(stats)\n }\n }\n emitter.on(`DEV_SSR_COMPILATION_DONE`, finish)\n devssrWebpackWatcher.resume()\n // Suspending is just a flag, so it's safe to re-suspend right away\n devssrWebpackWatcher.suspend()\n\n // Timeout after 1.5s.\n setTimeout(() => {\n isResolved = true\n resolve()\n }, 1500)\n })\n }\n\n // Wait for public/render-page.js to update w/ the page component.\n const found = await ensurePathComponentInSSRBundle(pageObj, directory)\n\n // If we can't find the page, just force set isClientOnlyPage\n // which skips rendering the body (so we just serve a shell)\n // and the page will render normally on the client.\n //\n // This only happens on the first time we try to render a page component\n // and it's taking a while to bundle its page component.\n if (!found) {\n isClientOnlyPage = true\n }\n\n // If the user added the query string `skip-ssr`, we always just render an empty shell.\n if (skipSsr) {\n isClientOnlyPage = true\n }\n\n try {\n const htmlString = await worker.renderHTML({\n path,\n componentPath: pageObj.component,\n htmlComponentRendererPath,\n directory,\n isClientOnlyPage,\n })\n return resolve(htmlString)\n } catch (error) {\n return reject(error)\n }\n })\n"],"file":"render-dev-html.js"}
1
+ {"version":3,"sources":["../../../src/utils/dev-ssr/render-dev-html.ts"],"names":["startWorker","newWorker","JestWorker","require","resolve","exposedMethods","numWorkers","forkOptions","silent","env","process","NODE_ENV","forceColors","GATSBY_EXPERIMENTAL_DEV_SSR","warmup","worker","initDevWorkerPool","changeCount","restartWorker","htmlComponentRendererPath","oldWorker","end","deleteModuleCache","searchFileForString","substring","filePath","Promise","escapedSubString","replace","chunkRegex","RegExp","stream","fs","createReadStream","found","on","d","test","toString","close","ensurePathComponentInSSRBundle","page","directory","report","panic","componentChunkName","readAttempts","searchForStringInterval","setInterval","clearInterval","renderDevHTML","path","skipSsr","store","reject","pageObj","getState","isClientOnlyPage","matchPath","boundActionCreators","createServerVisitedPage","devssrWebpackCompiler","devssrWebpackWatcher","needToRecompileSSRBundle","isResolved","finish","stats","emitter","off","resume","suspend","setTimeout","htmlString","renderHTML","componentPath","component","error"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,WAAW,GAAG,MAAW;AAC7B,QAAMC,SAAS,GAAG,IAAIC,mBAAJ,CAAeC,OAAO,CAACC,OAAR,CAAiB,yBAAjB,CAAf,EAA2D;AAC3EC,IAAAA,cAAc,EAAE,CAAE,YAAF,EAAgB,mBAAhB,EAAqC,QAArC,CAD2D;AAE3EC,IAAAA,UAAU,EAAE,CAF+D;AAG3EC,IAAAA,WAAW,EAAE;AACXC,MAAAA,MAAM,EAAE,KADG;AAEXC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jB;AACA,UAAM,IAAItC,OAAJ,CAAYtB,OAAO,IAAI;AAC3B,eAAS6D,MAAT,CAAgBC,KAAhB,EAAoC;AAClCC,uBAAQC,GAAR,CAAa,0BAAb,EAAwCH,MAAxC;;AACA,YAAI,CAACD,UAAL,EAAiB;AACf5D,UAAAA,OAAO,CAAC8D,KAAD,CAAP;AACD;AACF;;AACDC,qBAAQhC,EAAR,CAAY,0BAAZ,EAAuC8B,MAAvC;;AACAH,MAAAA,oBAAoB,CAACO,MAArB,GAR2B,CAS3B;;AACAP,MAAAA,oBAAoB,CAACQ,OAArB,GAV2B,CAY3B;;AACAC,MAAAA,UAAU,CAAC,MAAM;AACfP,QAAAA,UAAU,GAAG,IAAb;AACA5D,QAAAA,OAAO;AACR,OAHS,EAGP,IAHO,CAAV;AAID,KAjBK,CAAN;AAkBD,GA9DoC,CAgErC;;;AACA,QAAM8B,KAAK,GAAG,MAAMM,8BAA8B,CAACe,OAAD,EAAUb,SAAV,CAAlD,CAjEqC,CAmErC;AACA;AACA;AACA;AACA;AACA;;AACA,MAAI,CAACR,KAAL,EAAY;AACVuB,IAAAA,gBAAgB,GAAG,IAAnB;AACD,GA3EoC,CA6ErC;;;AACA,MAAIL,OAAJ,EAAa;AACXK,IAAAA,gBAAgB,GAAG,IAAnB;AACD;;AAED,MAAI;AACF,UAAMe,UAAU,GAAG,MAAMzD,MAAM,CAAC0D,UAAP,CAAkB;AACzCtB,MAAAA,IADyC;AAEzCuB,MAAAA,aAAa,EAAEnB,OAAO,CAACoB,SAFkB;AAGzCxD,MAAAA,yBAHyC;AAIzCuB,MAAAA,SAJyC;AAKzCe,MAAAA;AALyC,KAAlB,CAAzB;AAOA,WAAOrD,OAAO,CAACoE,UAAD,CAAd;AACD,GATD,CASE,OAAOI,KAAP,EAAc;AACd,WAAOtB,MAAM,CAACsB,KAAD,CAAb;AACD;AACF,CA9FD,CARK","sourcesContent":["import JestWorker from \"jest-worker\"\nimport fs from \"fs-extra\"\nimport { joinPath } from \"gatsby-core-utils\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport { isCI } from \"gatsby-core-utils\"\n\nimport { startListener } from \"../../bootstrap/requires-writer\"\nimport { findPageByPath } from \"../find-page-by-path\"\nimport { getPageData as getPageDataExperimental } from \"../get-page-data\"\nimport { getDevSSRWebpack } from \"../../commands/build-html\"\nimport { emitter } from \"../../redux\"\n\nconst startWorker = (): any => {\n const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), {\n exposedMethods: [`renderHTML`, `deleteModuleCache`, `warmup`],\n numWorkers: 1,\n forkOptions: {\n silent: false,\n env: {\n ...process.env,\n NODE_ENV: isCI() ? `production` : `development`,\n forceColors: true,\n GATSBY_EXPERIMENTAL_DEV_SSR: true,\n },\n },\n })\n\n // jest-worker is lazy with forking but we want to fork immediately so the user\n // doesn't have to wait.\n // @ts-ignore\n newWorker.warmup()\n\n return newWorker\n}\n\nlet worker\nexport const initDevWorkerPool = (): void => {\n worker = startWorker()\n}\n\nlet changeCount = 0\nexport const restartWorker = (htmlComponentRendererPath): void => {\n changeCount += 1\n // Forking is expensive — each time we re-require the outputted webpack\n // file, memory grows ~10 mb — 25 regenerations means ~250mb which seems\n // like an accepatable amount of memory to grow before we reclaim it\n // by rebooting the worker process.\n if (changeCount > 25) {\n const oldWorker = worker\n const newWorker = startWorker()\n worker = newWorker\n oldWorker.end()\n changeCount = 0\n } else {\n worker.deleteModuleCache(htmlComponentRendererPath)\n }\n}\n\nconst searchFileForString = (substring, filePath): Promise<boolean> =>\n new Promise(resolve => {\n const escapedSubString = substring.replace(/[.*+?^${}()|[\\]\\\\]/g, `\\\\$&`)\n\n // See if the chunk is in the newComponents array (not the notVisited).\n const chunkRegex = RegExp(\n `exports.ssrComponents.*${escapedSubString}.*}`,\n `gs`\n )\n const stream = fs.createReadStream(filePath)\n let found = false\n stream.on(`data`, function (d) {\n if (chunkRegex.test(d.toString())) {\n found = true\n stream.close()\n resolve(found)\n }\n })\n stream.on(`error`, function () {\n resolve(found)\n })\n stream.on(`close`, function () {\n resolve(found)\n })\n })\n\nconst ensurePathComponentInSSRBundle = async (\n page,\n directory\n): Promise<any> => {\n // This shouldn't happen.\n if (!page) {\n report.panic(`page not found`, page)\n }\n\n // Now check if it's written to public/render-page.js\n const htmlComponentRendererPath = joinPath(directory, `public/render-page.js`)\n // This search takes 1-10ms\n // We do it as there can be a race conditions where two pages\n // are requested at the same time which means that both are told render-page.js\n // has changed when the first page is complete meaning the second\n // page's component won't be in the render meaning its SSR will fail.\n let found = await searchFileForString(\n page.componentChunkName,\n htmlComponentRendererPath\n )\n\n if (!found) {\n await new Promise(resolve => {\n let readAttempts = 0\n const searchForStringInterval = setInterval(async () => {\n readAttempts += 1\n found = await searchFileForString(\n page.componentChunkName,\n htmlComponentRendererPath\n )\n if (found || readAttempts > 5) {\n clearInterval(searchForStringInterval)\n resolve()\n }\n }, 300)\n })\n }\n\n return found\n}\n\nexport const renderDevHTML = ({\n path,\n page,\n skipSsr = false,\n store,\n htmlComponentRendererPath,\n directory,\n}): Promise<string> =>\n new Promise(async (resolve, reject) => {\n startListener()\n let pageObj\n if (!page) {\n pageObj = findPageByPath(store.getState(), path)\n } else {\n pageObj = page\n }\n\n let isClientOnlyPage = false\n if (pageObj.matchPath) {\n isClientOnlyPage = true\n }\n\n const { boundActionCreators } = require(`../../redux/actions`)\n const { createServerVisitedPage } = boundActionCreators\n // Record this page was requested. This will kick off adding its page\n // component to the ssr bundle (if that's not already happened)\n createServerVisitedPage(pageObj.componentChunkName)\n\n // Ensure the query has been run and written out.\n try {\n await getPageDataExperimental(pageObj.path)\n } catch {\n // If we can't get the page, it was probably deleted recently\n // so let's just do a 404 page.\n return reject(`404 page`)\n }\n\n // Resume the webpack watcher and wait for any compilation necessary to happen.\n // We timeout after 1.5s as the user might not care per se about SSR.\n //\n // We pause and resume so there's no excess webpack activity during normal development.\n const {\n devssrWebpackCompiler,\n devssrWebpackWatcher,\n needToRecompileSSRBundle,\n } = getDevSSRWebpack()\n if (\n devssrWebpackWatcher &&\n devssrWebpackCompiler &&\n needToRecompileSSRBundle\n ) {\n let isResolved = false\n await new Promise(resolve => {\n function finish(stats: Stats): void {\n emitter.off(`DEV_SSR_COMPILATION_DONE`, finish)\n if (!isResolved) {\n resolve(stats)\n }\n }\n emitter.on(`DEV_SSR_COMPILATION_DONE`, finish)\n devssrWebpackWatcher.resume()\n // Suspending is just a flag, so it's safe to re-suspend right away\n devssrWebpackWatcher.suspend()\n\n // Timeout after 1.5s.\n setTimeout(() => {\n isResolved = true\n resolve()\n }, 1500)\n })\n }\n\n // Wait for public/render-page.js to update w/ the page component.\n const found = await ensurePathComponentInSSRBundle(pageObj, directory)\n\n // If we can't find the page, just force set isClientOnlyPage\n // which skips rendering the body (so we just serve a shell)\n // and the page will render normally on the client.\n //\n // This only happens on the first time we try to render a page component\n // and it's taking a while to bundle its page component.\n if (!found) {\n isClientOnlyPage = true\n }\n\n // If the user added the query string `skip-ssr`, we always just render an empty shell.\n if (skipSsr) {\n isClientOnlyPage = true\n }\n\n try {\n const htmlString = await worker.renderHTML({\n path,\n componentPath: pageObj.component,\n htmlComponentRendererPath,\n directory,\n isClientOnlyPage,\n })\n return resolve(htmlString)\n } catch (error) {\n return reject(error)\n }\n })\n"],"file":"render-dev-html.js"}
@@ -41,7 +41,7 @@ async function appendPreloadHeaders(requestPath, res) {
41
41
  const staticQueriesToPreload = new Set();
42
42
 
43
43
  for (const pagePath of pagePathsToPreload) {
44
- res.append(`Link`, `</${path.join(`page-data`, (0, _pageData.fixedPagePath)(pagePath), `page-data.json`)}>; rel=preload; as=fetch ; crossorigin`);
44
+ res.append(`Link`, `</${path.join(`page-data`, encodeURI((0, _pageData.fixedPagePath)(pagePath)), `page-data.json`)}>; rel=preload; as=fetch ; crossorigin`);
45
45
 
46
46
  try {
47
47
  const pageData = await (0, _pageData.readPageData)(path.join(_redux.store.getState().program.directory, `public`), pagePath); // iterate over needed static queries and add them to Set of static queries to preload
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/develop-preload-headers.ts"],"names":["appendPreloadHeaders","requestPath","res","append","page","store","getState","pagePathsToPreload","includes","path","unshift","staticQueriesToPreload","Set","pagePath","join","pageData","program","directory","staticQueryHash","staticQueryHashes","add","e"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,eAAeA,oBAAf,CACLC,WADK,EAELC,GAFK,EAGU;AACf;AACA;AACAA,EAAAA,GAAG,CAACC,MAAJ,CAAY,MAAZ,EAAoB,uCAApB;AACAD,EAAAA,GAAG,CAACC,MAAJ,CAAY,MAAZ,EAAoB,mDAApB;AAEA,QAAMC,IAAI,GAAG,oCAAeC,aAAMC,QAAN,EAAf,EAAiCL,WAAjC,EAA8C,IAA9C,CAAb,CANe,CAOf;AACA;;AACA,MAAIG,IAAJ,EAAU;AACR;AACAF,IAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,iEAFH,EAFQ,CAOR;AACA;;AACA,UAAMI,kBAAkB,GAAG,CAAE,WAAF,EAAe,gBAAf,CAA3B;;AACA,QAAI,CAACA,kBAAkB,CAACC,QAAnB,CAA4BJ,IAAI,CAACK,IAAjC,CAAL,EAA6C;AAC3C;AACAF,MAAAA,kBAAkB,CAACG,OAAnB,CAA2BN,IAAI,CAACK,IAAhC;AACD;;AAED,UAAME,sBAAsB,GAAG,IAAIC,GAAJ,EAA/B;;AACA,SAAK,MAAMC,QAAX,IAAuBN,kBAAvB,EAA2C;AACzCL,MAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,KAAIM,IAAI,CAACK,IAAL,CACF,WADE,EAEH,6BAAcD,QAAd,CAFG,EAGF,gBAHE,CAIH,wCANJ;;AASA,UAAI;AACF,cAAME,QAAQ,GAAG,MAAM,4BACrBN,IAAI,CAACK,IAAL,CAAUT,aAAMC,QAAN,GAAiBU,OAAjB,CAAyBC,SAAnC,EAA+C,QAA/C,CADqB,EAErBJ,QAFqB,CAAvB,CADE,CAMF;AACA;;AACA,aAAK,MAAMK,eAAX,IAA8BH,QAAQ,CAACI,iBAAvC,EAA0D;AACxDR,UAAAA,sBAAsB,CAACS,GAAvB,CAA2BF,eAA3B;AACD;AACF,OAXD,CAWE,OAAOG,CAAP,EAAU,CACV;AACA;AACA;AACD;AACF,KA1CO,CA4CR;;;AACA,SAAK,MAAMH,eAAX,IAA8BP,sBAA9B,EAAsD;AACpDT,MAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,oBAAmBe,eAAgB,6CAFtC;AAID;AACF,GAnDD,MAmDO,CACL;AACA;AACD;AACF","sourcesContent":["import { Response } from \"express\"\nimport * as path from \"path\"\n\nimport { findPageByPath } from \"./find-page-by-path\"\nimport { fixedPagePath, readPageData } from \"./page-data\"\nimport { store } from \"../redux\"\n\n/**\n * Add preload link headers to responses for .html files. This allows browser to schedule fetching critical resources\n * to render a page faster. Without them it would result in network waterfall (fetch js script -> parse and execute -> start downloading data)\n * With them we can start downloading data before JS executes.\n */\nexport async function appendPreloadHeaders(\n requestPath: string,\n res: Response\n): Promise<void> {\n // add common.js and socket.io.js preload headers\n // TODO: make socket.io part not blocking - we don't need it anymore to render the page\n res.append(`Link`, `</commons.js>; rel=preload; as=script`)\n res.append(`Link`, `</socket.io/socket.io.js>; rel=preload; as=script`)\n\n const page = findPageByPath(store.getState(), requestPath, true)\n // we fallback to 404 pages - so there should always be a page (at worst dev-404)\n // this is just sanity check to not crash server in case it doesn't find anything\n if (page) {\n // add app-data.json preload\n res.append(\n `Link`,\n `</page-data/app-data.json>; rel=preload; as=fetch ; crossorigin`\n )\n\n // add page-data.json preload\n // our runtime also demands 404 and dev-404 page-data to be fetched to even render (see cache-dir/app.js)\n const pagePathsToPreload = [`/404.html`, `/dev-404-page/`]\n if (!pagePathsToPreload.includes(page.path)) {\n // let's make sure page path is first one (order shouldn't matter, just for reasonable order)\n pagePathsToPreload.unshift(page.path)\n }\n\n const staticQueriesToPreload = new Set<string>()\n for (const pagePath of pagePathsToPreload) {\n res.append(\n `Link`,\n `</${path.join(\n `page-data`,\n fixedPagePath(pagePath),\n `page-data.json`\n )}>; rel=preload; as=fetch ; crossorigin`\n )\n\n try {\n const pageData = await readPageData(\n path.join(store.getState().program.directory, `public`),\n pagePath\n )\n\n // iterate over needed static queries and add them to Set of static queries to preload\n // Set will guarantee uniqueness in case queries are shared by requested page and 404 page.\n for (const staticQueryHash of pageData.staticQueryHashes) {\n staticQueriesToPreload.add(staticQueryHash)\n }\n } catch (e) {\n // there might be timing reasons why this fails - page-data file is not created yet\n // as page was just recently added (so page exists already but page-data doesn't yet)\n // in those cases we just do nothing\n }\n }\n\n // append accumulated static queries from pages we load\n for (const staticQueryHash of staticQueriesToPreload) {\n res.append(\n `Link`,\n `</page-data/sq/d/${staticQueryHash}.json>; rel=preload; as=fetch ; crossorigin`\n )\n }\n } else {\n // should we track cases when there is actually nothing returned to find cases\n // where we don't add preload headers if above assumption turns out to be wrong?\n }\n}\n"],"file":"develop-preload-headers.js"}
1
+ {"version":3,"sources":["../../src/utils/develop-preload-headers.ts"],"names":["appendPreloadHeaders","requestPath","res","append","page","store","getState","pagePathsToPreload","includes","path","unshift","staticQueriesToPreload","Set","pagePath","join","encodeURI","pageData","program","directory","staticQueryHash","staticQueryHashes","add","e"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,eAAeA,oBAAf,CACLC,WADK,EAELC,GAFK,EAGU;AACf;AACA;AACAA,EAAAA,GAAG,CAACC,MAAJ,CAAY,MAAZ,EAAoB,uCAApB;AACAD,EAAAA,GAAG,CAACC,MAAJ,CAAY,MAAZ,EAAoB,mDAApB;AAEA,QAAMC,IAAI,GAAG,oCAAeC,aAAMC,QAAN,EAAf,EAAiCL,WAAjC,EAA8C,IAA9C,CAAb,CANe,CAOf;AACA;;AACA,MAAIG,IAAJ,EAAU;AACR;AACAF,IAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,iEAFH,EAFQ,CAOR;AACA;;AACA,UAAMI,kBAAkB,GAAG,CAAE,WAAF,EAAe,gBAAf,CAA3B;;AACA,QAAI,CAACA,kBAAkB,CAACC,QAAnB,CAA4BJ,IAAI,CAACK,IAAjC,CAAL,EAA6C;AAC3C;AACAF,MAAAA,kBAAkB,CAACG,OAAnB,CAA2BN,IAAI,CAACK,IAAhC;AACD;;AAED,UAAME,sBAAsB,GAAG,IAAIC,GAAJ,EAA/B;;AACA,SAAK,MAAMC,QAAX,IAAuBN,kBAAvB,EAA2C;AACzCL,MAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,KAAIM,IAAI,CAACK,IAAL,CACF,WADE,EAEHC,SAAS,CAAC,6BAAcF,QAAd,CAAD,CAFN,EAGF,gBAHE,CAIH,wCANJ;;AASA,UAAI;AACF,cAAMG,QAAQ,GAAG,MAAM,4BACrBP,IAAI,CAACK,IAAL,CAAUT,aAAMC,QAAN,GAAiBW,OAAjB,CAAyBC,SAAnC,EAA+C,QAA/C,CADqB,EAErBL,QAFqB,CAAvB,CADE,CAMF;AACA;;AACA,aAAK,MAAMM,eAAX,IAA8BH,QAAQ,CAACI,iBAAvC,EAA0D;AACxDT,UAAAA,sBAAsB,CAACU,GAAvB,CAA2BF,eAA3B;AACD;AACF,OAXD,CAWE,OAAOG,CAAP,EAAU,CACV;AACA;AACA;AACD;AACF,KA1CO,CA4CR;;;AACA,SAAK,MAAMH,eAAX,IAA8BR,sBAA9B,EAAsD;AACpDT,MAAAA,GAAG,CAACC,MAAJ,CACG,MADH,EAEG,oBAAmBgB,eAAgB,6CAFtC;AAID;AACF,GAnDD,MAmDO,CACL;AACA;AACD;AACF","sourcesContent":["import { Response } from \"express\"\nimport * as path from \"path\"\n\nimport { findPageByPath } from \"./find-page-by-path\"\nimport { fixedPagePath, readPageData } from \"./page-data\"\nimport { store } from \"../redux\"\n\n/**\n * Add preload link headers to responses for .html files. This allows browser to schedule fetching critical resources\n * to render a page faster. Without them it would result in network waterfall (fetch js script -> parse and execute -> start downloading data)\n * With them we can start downloading data before JS executes.\n */\nexport async function appendPreloadHeaders(\n requestPath: string,\n res: Response\n): Promise<void> {\n // add common.js and socket.io.js preload headers\n // TODO: make socket.io part not blocking - we don't need it anymore to render the page\n res.append(`Link`, `</commons.js>; rel=preload; as=script`)\n res.append(`Link`, `</socket.io/socket.io.js>; rel=preload; as=script`)\n\n const page = findPageByPath(store.getState(), requestPath, true)\n // we fallback to 404 pages - so there should always be a page (at worst dev-404)\n // this is just sanity check to not crash server in case it doesn't find anything\n if (page) {\n // add app-data.json preload\n res.append(\n `Link`,\n `</page-data/app-data.json>; rel=preload; as=fetch ; crossorigin`\n )\n\n // add page-data.json preload\n // our runtime also demands 404 and dev-404 page-data to be fetched to even render (see cache-dir/app.js)\n const pagePathsToPreload = [`/404.html`, `/dev-404-page/`]\n if (!pagePathsToPreload.includes(page.path)) {\n // let's make sure page path is first one (order shouldn't matter, just for reasonable order)\n pagePathsToPreload.unshift(page.path)\n }\n\n const staticQueriesToPreload = new Set<string>()\n for (const pagePath of pagePathsToPreload) {\n res.append(\n `Link`,\n `</${path.join(\n `page-data`,\n encodeURI(fixedPagePath(pagePath)),\n `page-data.json`\n )}>; rel=preload; as=fetch ; crossorigin`\n )\n\n try {\n const pageData = await readPageData(\n path.join(store.getState().program.directory, `public`),\n pagePath\n )\n\n // iterate over needed static queries and add them to Set of static queries to preload\n // Set will guarantee uniqueness in case queries are shared by requested page and 404 page.\n for (const staticQueryHash of pageData.staticQueryHashes) {\n staticQueriesToPreload.add(staticQueryHash)\n }\n } catch (e) {\n // there might be timing reasons why this fails - page-data file is not created yet\n // as page was just recently added (so page exists already but page-data doesn't yet)\n // in those cases we just do nothing\n }\n }\n\n // append accumulated static queries from pages we load\n for (const staticQueryHash of staticQueriesToPreload) {\n res.append(\n `Link`,\n `</page-data/sq/d/${staticQueryHash}.json>; rel=preload; as=fetch ; crossorigin`\n )\n }\n } else {\n // should we track cases when there is actually nothing returned to find cases\n // where we don't add preload headers if above assumption turns out to be wrong?\n }\n}\n"],"file":"develop-preload-headers.js"}