Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): move starting dev-ssr listener inside function & only init listeners once #28395

Merged
merged 2 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions packages/gatsby/src/bootstrap/requires-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,29 @@ const debouncedWriteAll = _.debounce(
}
)

if (process.env.GATSBY_EXPERIMENTAL_DEV_SSR) {
/**
* Start listening to CREATE_SERVER_VISITED_PAGE events so we can rewrite
* files as required
*/
emitter.on(`CREATE_SERVER_VISITED_PAGE`, (): void => {
reporter.pendingActivity({ id: `requires-writer` })
debouncedWriteAll()
})
}

/**
* Start listening to CREATE/DELETE_PAGE events so we can rewrite
* files as required
*/
let listenerStarted = false
export const startListener = (): void => {
// Only start the listener once.
if (listenerStarted) {
return
}
listenerStarted = true

if (process.env.GATSBY_EXPERIMENTAL_DEV_SSR) {
/**
* Start listening to CREATE_SERVER_VISITED_PAGE events so we can rewrite
* files as required
*/
emitter.on(`CREATE_SERVER_VISITED_PAGE`, (): void => {
reporter.pendingActivity({ id: `requires-writer` })
debouncedWriteAll()
})
}

emitter.on(`CREATE_PAGE`, (): void => {
reporter.pendingActivity({ id: `requires-writer` })
debouncedWriteAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Object {
],
"message": "The following flags are active:
- ALL_COMMANDS · (Umbrella Issue (test)) · test

There are 5 other flags available that you might be interested in:
- FAST_DEV · Enable all experiments aimed at improving develop server start time
- 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.
- 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.
- ONLY_BUILDS · (Umbrella Issue (test)) · test
- YET_ANOTHER · (Umbrella Issue (test)) · test
Comment on lines +16 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? And why unit tests passes here without any changes to tests? did we merge something that didn't update snapshot?

",
"unknownFlagMessage": "The following flag(s) found in your gatsby-config.js are not known:
- FASTLY_DEV (did you mean: FAST_DEV)
Expand Down