Skip to content

Commit 66c8c7d

Browse files
KyleAMathewspieh
authored andcommitted
fix(gatsby): move starting dev-ssr listener inside function & only init listeners once (#28395)
* fix(gatsby): move starting dev-ssr listener inside function & only init listeners once * fix snapshot (cherry picked from commit 3ce476b)
1 parent d6129b1 commit 66c8c7d

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

packages/gatsby/src/bootstrap/requires-writer.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,22 +321,29 @@ const debouncedWriteAll = _.debounce(
321321
}
322322
)
323323

324-
if (process.env.GATSBY_EXPERIMENTAL_DEV_SSR) {
325-
/**
326-
* Start listening to CREATE_SERVER_VISITED_PAGE events so we can rewrite
327-
* files as required
328-
*/
329-
emitter.on(`CREATE_SERVER_VISITED_PAGE`, (): void => {
330-
reporter.pendingActivity({ id: `requires-writer` })
331-
debouncedWriteAll()
332-
})
333-
}
334-
335324
/**
336325
* Start listening to CREATE/DELETE_PAGE events so we can rewrite
337326
* files as required
338327
*/
328+
let listenerStarted = false
339329
export const startListener = (): void => {
330+
// Only start the listener once.
331+
if (listenerStarted) {
332+
return
333+
}
334+
listenerStarted = true
335+
336+
if (process.env.GATSBY_EXPERIMENTAL_DEV_SSR) {
337+
/**
338+
* Start listening to CREATE_SERVER_VISITED_PAGE events so we can rewrite
339+
* files as required
340+
*/
341+
emitter.on(`CREATE_SERVER_VISITED_PAGE`, (): void => {
342+
reporter.pendingActivity({ id: `requires-writer` })
343+
debouncedWriteAll()
344+
})
345+
}
346+
340347
emitter.on(`CREATE_PAGE`, (): void => {
341348
reporter.pendingActivity({ id: `requires-writer` })
342349
debouncedWriteAll()

packages/gatsby/src/utils/__tests__/__snapshots__/handle-flags.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Object {
1313
],
1414
"message": "The following flags are active:
1515
- ALL_COMMANDS · (Umbrella Issue (test)) · test
16+
17+
There are 5 other flags available that you might be interested in:
18+
- FAST_DEV · Enable all experiments aimed at improving develop server start time
19+
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
20+
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
21+
- ONLY_BUILDS · (Umbrella Issue (test)) · test
22+
- YET_ANOTHER · (Umbrella Issue (test)) · test
1623
",
1724
"unknownFlagMessage": "The following flag(s) found in your gatsby-config.js are not known:
1825
- FASTLY_DEV (did you mean: FAST_DEV)

0 commit comments

Comments
 (0)