Skip to content

Commit a612f26

Browse files
authored
feat(gatsby): invite (1%) of Gatsby users to try out develop ssr (#28139)
* feat(gatsby): invite (1%) of Gatsby users to try out develop ssr * fix
1 parent 04349a0 commit a612f26

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

packages/gatsby/src/services/initialize.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import telemetry from "gatsby-telemetry"
99

1010
import apiRunnerNode from "../utils/api-runner-node"
1111
import { getBrowsersList } from "../utils/browserslist"
12+
import { showExperimentNoticeAfterTimeout } from "../utils/show-experiment-notice"
13+
import sampleSiteForExperiment from "../utils/sample-site-for-experiment"
1214
import { Store, AnyAction } from "redux"
1315
import { preferDefault } from "../bootstrap/prefer-default"
1416
import * as WorkerPool from "../utils/worker/pool"
@@ -30,6 +32,31 @@ interface IPluginResolution {
3032
options: IPluginInfoOptions
3133
}
3234

35+
if (
36+
process.env.gatsby_executing_command === `develop` &&
37+
!process.env.GATSBY_EXPERIMENTAL_DEV_SSR &&
38+
!isCI() &&
39+
sampleSiteForExperiment(`DEV_SSR`, 1)
40+
) {
41+
showExperimentNoticeAfterTimeout(
42+
`devSSR`,
43+
`
44+
Your dev experience is about to get better, faster, and stronger!
45+
46+
We'll soon be shipping support for SSR in development.
47+
48+
This will help the dev environment more closely mimic builds so you'll catch build errors earlier and fix them faster.
49+
50+
Try out develop SSR *today* by running your site with it enabled:
51+
52+
GATSBY_EXPERIMENT_DEV_SSR=true gatsby develop
53+
54+
Please let us know how it goes good, bad, or otherwise at gatsby.dev/dev-ssr-feedback
55+
`,
56+
1 // Show this immediately to the subset of sites selected.
57+
)
58+
}
59+
3360
// Show stack trace on unhandled promises.
3461
process.on(`unhandledRejection`, (reason: unknown) => {
3562
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33636
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 1`] = `true`;
4+
5+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 2`] = `false`;
6+
7+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 3`] = `true`;
8+
9+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 4`] = `true`;
10+
11+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 5`] = `false`;
12+
13+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 6`] = `true`;
14+
15+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 7`] = `false`;
16+
17+
exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 8`] = `false`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sampleSiteForExperiment from "../sample-site-for-experiment"
2+
3+
describe(`sampleSiteForExperiment`, () => {
4+
it(`returns true or false depending on if they randomly are bucketed in or not`, () => {
5+
const experiments = [`a`, `b`, `c`, `d`, `e`, `f`, `h`, `i`]
6+
experiments.forEach(experiment => {
7+
expect(sampleSiteForExperiment(experiment, 0)).toBeFalsy()
8+
expect(sampleSiteForExperiment(experiment, 50)).toMatchSnapshot()
9+
expect(sampleSiteForExperiment(experiment, 100)).toBeTruthy()
10+
})
11+
})
12+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getRepositoryId } from "gatsby-telemetry/lib/repository-id"
2+
import { murmurhash } from "babel-plugin-remove-graphql-queries"
3+
4+
const sampleSite = (experimentName: string, percentage: number): boolean =>
5+
murmurhash(
6+
experimentName + `` + JSON.stringify(getRepositoryId().repositoryId)
7+
) %
8+
100 <
9+
percentage
10+
11+
export default sampleSite

0 commit comments

Comments
 (0)