Skip to content

Commit

Permalink
feat(gatsby): invite (1%) of Gatsby users to try out develop ssr (#28139
Browse files Browse the repository at this point in the history
)

* feat(gatsby): invite (1%) of Gatsby users to try out develop ssr

* fix
  • Loading branch information
KyleAMathews authored Nov 18, 2020
1 parent 04349a0 commit a612f26
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import telemetry from "gatsby-telemetry"

import apiRunnerNode from "../utils/api-runner-node"
import { getBrowsersList } from "../utils/browserslist"
import { showExperimentNoticeAfterTimeout } from "../utils/show-experiment-notice"
import sampleSiteForExperiment from "../utils/sample-site-for-experiment"
import { Store, AnyAction } from "redux"
import { preferDefault } from "../bootstrap/prefer-default"
import * as WorkerPool from "../utils/worker/pool"
Expand All @@ -30,6 +32,31 @@ interface IPluginResolution {
options: IPluginInfoOptions
}

if (
process.env.gatsby_executing_command === `develop` &&
!process.env.GATSBY_EXPERIMENTAL_DEV_SSR &&
!isCI() &&
sampleSiteForExperiment(`DEV_SSR`, 1)
) {
showExperimentNoticeAfterTimeout(
`devSSR`,
`
Your dev experience is about to get better, faster, and stronger!
We'll soon be shipping support for SSR in development.
This will help the dev environment more closely mimic builds so you'll catch build errors earlier and fix them faster.
Try out develop SSR *today* by running your site with it enabled:
GATSBY_EXPERIMENT_DEV_SSR=true gatsby develop
Please let us know how it goes good, bad, or otherwise at gatsby.dev/dev-ssr-feedback
`,
1 // Show this immediately to the subset of sites selected.
)
}

// Show stack trace on unhandled promises.
process.on(`unhandledRejection`, (reason: unknown) => {
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33636
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 1`] = `true`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 2`] = `false`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 3`] = `true`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 4`] = `true`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 5`] = `false`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 6`] = `true`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 7`] = `false`;

exports[`sampleSiteForExperiment returns true or false depending on if they randomly are bucketed in or not 8`] = `false`;
12 changes: 12 additions & 0 deletions packages/gatsby/src/utils/__tests__/sample-site-for-experiment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sampleSiteForExperiment from "../sample-site-for-experiment"

describe(`sampleSiteForExperiment`, () => {
it(`returns true or false depending on if they randomly are bucketed in or not`, () => {
const experiments = [`a`, `b`, `c`, `d`, `e`, `f`, `h`, `i`]
experiments.forEach(experiment => {
expect(sampleSiteForExperiment(experiment, 0)).toBeFalsy()
expect(sampleSiteForExperiment(experiment, 50)).toMatchSnapshot()
expect(sampleSiteForExperiment(experiment, 100)).toBeTruthy()
})
})
})
11 changes: 11 additions & 0 deletions packages/gatsby/src/utils/sample-site-for-experiment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getRepositoryId } from "gatsby-telemetry/lib/repository-id"
import { murmurhash } from "babel-plugin-remove-graphql-queries"

const sampleSite = (experimentName: string, percentage: number): boolean =>
murmurhash(
experimentName + `` + JSON.stringify(getRepositoryId().repositoryId)
) %
100 <
percentage

export default sampleSite

0 comments on commit a612f26

Please sign in to comment.