Skip to content

Commit 04349a0

Browse files
KyleAMathewswardpeetpieh
authored
feat(gatsby): lazy bundle page components in dev server (#27884)
* feat(gatsby): lazy compile page components in dev server This means we only compile the core runtime code initially — page components are only compiled when the user visits the page. * Fix lint * Cleanup logs * cleanups * fix tests * Don't bother with navigating — if webpack doesn't update — the user probably has errors in their code or something bigger is wrong so let them just refresh, etc. * Update packages/gatsby/src/bootstrap/requires-writer.ts Co-authored-by: Ward Peeters <[email protected]> * Update packages/gatsby/cache-dir/dev-loader.js Co-authored-by: Ward Peeters <[email protected]> * Fix lint error * Wait until we know staticQueryHashes are written to page-data.json files We only discover static queries for pages after the component is compiled. Which means when we lazily add page components, we initially don't know what static queries should be loaded. To track this, we mark page-data.json files as not bundled & only after the staticQueryHashes is written do we accept the page as loaded. * Disable check in production * Only trigger compilation/page writing once * Also pull xhr loaded static queries for <StaticQuery> * instance isn't defined in builds apparently * Work around webpack hot reloading bug * For static queries, data pushed from websocket is the most fresh * Centralize logic and prevent it from repeatedly hitting the backend * fix ordering of merge * Comment and add timeout to ensure page-data writes happen after the webpack compilation * Only add notInDevBundle during development * Add back mistakenly removed code * Didn't need this * Implement @pieh's idea for telling runtime that dev bundle is loaded * Fix tests * Remove logs * Put changes behind GATSBY_EXPERIMENT_LAZY_DEVJS flag * Add temporary fork of development-runtime tests for lazy devjs PR * Remove duplicated tests w/ cleaner method @pieh suggested * Address @pieh feedback * Update packages/gatsby/src/utils/start-server.ts Co-authored-by: Michal Piechowiak <[email protected]> * Remove global middleware * This isn't true * fix lint Co-authored-by: Ward Peeters <[email protected]> Co-authored-by: Michal Piechowiak <[email protected]>
1 parent 179694a commit 04349a0

File tree

18 files changed

+942
-15
lines changed

18 files changed

+942
-15
lines changed

.circleci/config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ aliases:
117117
- notify-status:
118118
condition: << parameters.nightly >>
119119

120+
e2e_tests_development_runtime_lazy_alias:
121+
&e2e_tests_development_runtime_lazy_alias
122+
<<: *e2e-executor
123+
parameters:
124+
nightly:
125+
type: boolean
126+
default: false
127+
environment:
128+
CYPRESS_PROJECT_ID: ihj5mz
129+
CYPRESS_RECORD_KEY: 01acdce8-75bd-4280-9839-6cb215b2c84b
130+
steps:
131+
- e2e-test:
132+
test_path: e2e-tests/lazy-development-runtime
133+
skip_file_change_test: << parameters.nightly >>
134+
- notify-status:
135+
condition: << parameters.nightly >>
136+
120137
e2e_tests_gatsby-image_alias: &e2e_tests_gatsby-image_alias
121138
<<: *e2e-executor
122139
parameters:
@@ -332,6 +349,13 @@ jobs:
332349
e2e_tests_development_runtime:
333350
<<: *e2e_tests_development_runtime_alias
334351

352+
e2e_tests_development_runtime_lazy_devjs:
353+
<<: *e2e_tests_development_runtime_alias
354+
environment:
355+
GATSBY_EXPERIMENT_LAZY_DEVJS: true
356+
CYPRESS_PROJECT_ID: ihj5mz
357+
CYPRESS_RECORD_KEY: 01acdce8-75bd-4280-9839-6cb215b2c84b
358+
335359
e2e_tests_development_runtime_with_experimental_react:
336360
<<: *e2e_tests_development_runtime_alias
337361

@@ -605,6 +629,8 @@ workflows:
605629
<<: *e2e-test-workflow
606630
- e2e_tests_development_runtime:
607631
<<: *e2e-test-workflow
632+
- e2e_tests_development_runtime_lazy_devjs:
633+
<<: *e2e-test-workflow
608634
- e2e_tests_production_runtime:
609635
<<: *e2e-test-workflow
610636
- themes_e2e_tests_production_runtime:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Dev loader loadPage should be successful when component can be loaded 1`] = `
4+
Object {
5+
"component": Object {
6+
"chunkName": "bar",
7+
},
8+
"json": Object {
9+
"pageContext": "something something",
10+
},
11+
"page": Object {
12+
"componentChunkName": "chunk",
13+
"matchPath": undefined,
14+
"path": "/mypage/",
15+
"staticQueryHashes": Array [],
16+
"webpackCompilationHash": "123",
17+
},
18+
"staticQueryResults": Object {},
19+
}
20+
`;

0 commit comments

Comments
 (0)