Skip to content

Commit a9d65f6

Browse files
piehvladar
andauthored
fix(gatsby): workaround some webpack issues causing first save after running gatsby develop to not have any effect (#30193)
* fix(gatsby): wokraround some webpack issues causing first save after running gatsby develop to not have any effect * adjust unit tests to mock extra fs method * Update packages/gatsby/src/utils/gatsby-webpack-virtual-modules.ts Co-authored-by: Vladimir Razuvaev <[email protected]> * format Co-authored-by: Vladimir Razuvaev <[email protected]>
1 parent 14da60a commit a9d65f6

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

packages/gatsby/src/bootstrap/__tests__/requires-writer.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const generatePagesState = pages => {
2020
jest.mock(`fs-extra`, () => {
2121
return {
2222
writeFile: () => Promise.resolve(),
23+
outputFileSync: () => {},
2324
move: () => {},
2425
}
2526
})

packages/gatsby/src/utils/gatsby-webpack-virtual-modules.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import VirtualModulesPlugin from "webpack-virtual-modules"
22
import * as path from "path"
3+
import * as fs from "fs-extra"
34
/*
45
* This module allows creating virtual (in memory only) modules / files
56
* that webpack compilation can access without the need to write module
@@ -46,6 +47,10 @@ export function writeModule(filePath: string, fileContents: string): void {
4647
return
4748
}
4849

50+
// workaround webpack marking virtual modules as deleted because those files don't really exist
51+
// so we create those files just so watchpack doesn't mark them as initially missing
52+
fs.outputFileSync(adjustedFilePath, fileContents)
53+
4954
fileContentLookup[adjustedFilePath] = fileContents
5055

5156
instances.forEach(instance => {

packages/gatsby/src/utils/start-server.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export async function startServer(
7878
})
7979
webpackActivity.start()
8080

81+
// loading indicator
82+
// write virtual module always to not fail webpack compilation, but only add express route handlers when
83+
// query on demand is enabled and loading indicator is not disabled
84+
writeVirtualLoadingIndicatorModule()
85+
8186
const THIRTY_SECONDS = 30 * 1000
8287
let cancelDevJSNotice: CancelExperimentNoticeCallbackOrUndefined
8388
if (
@@ -486,10 +491,6 @@ module.exports = {
486491
route({ app, program, store })
487492
}
488493

489-
// loading indicator
490-
// write virtual module always to not fail webpack compilation, but only add express route handlers when
491-
// query on demand is enabled and loading indicator is not disabled
492-
writeVirtualLoadingIndicatorModule()
493494
if (
494495
process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
495496
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true`

0 commit comments

Comments
 (0)