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

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

Merged
merged 2 commits into from
Nov 18, 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: 28 additions & 1 deletion packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from "lodash"
import { slash } from "gatsby-core-utils"
import { slash, isCI } from "gatsby-core-utils"
import fs from "fs-extra"
import md5File from "md5-file"
import crypto from "crypto"
Expand All @@ -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