-
Notifications
You must be signed in to change notification settings - Fork 10.3k
feature(gatsby): Pause dev-ssr watching between page loads to avoid slowing down regular develop-js HMR #28394
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
Merged
+83
−2
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ee315ed
feature(gatsby): Pause dev-ssr watching between page loads to avoid s…
KyleAMathews b94ced1
update snapshot
KyleAMathews 0228936
Don't double-resolve + add activity for building the SSR bundle
KyleAMathews 135e960
Merge remote-tracking branch 'origin/master' into lazy-compile
KyleAMathews b96c520
Add timeout for tests to ensure that dev server has time to bundle SS…
KyleAMathews fee4f5a
Merge remote-tracking branch 'origin/master' into lazy-compile
KyleAMathews e8aef42
Update packages/gatsby/src/commands/build-html.ts
KyleAMathews f197219
fix typo
KyleAMathews ed4b4eb
Don't resume if nothing has changed
KyleAMathews 740a1c1
Update packages/gatsby/src/commands/build-html.ts
KyleAMathews b5bda6c
Didn't need this
KyleAMathews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import report from "gatsby-cli/lib/reporter" | |
| import { startListener } from "../../bootstrap/requires-writer" | ||
| import { findPageByPath } from "../find-page-by-path" | ||
| import { getPageData as getPageDataExperimental } from "../get-page-data" | ||
| import { getDevSSRWebpack } from "../../commands/build-html" | ||
| import { emitter } from "../../redux" | ||
|
|
||
| const startWorker = (): any => { | ||
| const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), { | ||
|
|
@@ -144,6 +146,41 @@ export const renderDevHTML = ({ | |
| return reject(`404 page`) | ||
| } | ||
|
|
||
| // Resume the webpack watcher and wait for any compilation necessary to happen. | ||
| // We timeout after 1.5s as the user might not care per se about SSR. | ||
| // | ||
| // We pause and resume so there's no excess webpack activity during normal development. | ||
| const { | ||
| devssrWebpackCompiler, | ||
| devssrWebpackWatcher, | ||
| needToRecompileSSRBundle, | ||
| } = getDevSSRWebpack() | ||
| if ( | ||
| devssrWebpackWatcher && | ||
| devssrWebpackCompiler && | ||
| needToRecompileSSRBundle | ||
| ) { | ||
| let isResolved = false | ||
| await new Promise(resolve => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ascorbic this pattern is swwweeeeet
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The resume/suspend stuff |
||
| function finish(stats: Stats): void { | ||
| emitter.off(`DEV_SSR_COMPILATION_DONE`, finish) | ||
| if (!isResolved) { | ||
| resolve(stats) | ||
| } | ||
| } | ||
| emitter.on(`DEV_SSR_COMPILATION_DONE`, finish) | ||
| devssrWebpackWatcher.resume() | ||
| // Suspending is just a flag, so it's safe to re-suspend right away | ||
| devssrWebpackWatcher.suspend() | ||
|
|
||
| // Timeout after 1.5s. | ||
| setTimeout(() => { | ||
| isResolved = true | ||
| resolve() | ||
| }, 1500) | ||
| }) | ||
| } | ||
|
|
||
| // Wait for public/render-page.js to update w/ the page component. | ||
| const found = await ensurePathComponentInSSRBundle(pageObj, directory) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.