Skip to content

Commit b81e6bd

Browse files
authored
fix(gatsby): Only set auto optin flags if not in config (#28627)
1 parent 1dcbc09 commit b81e6bd

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

packages/gatsby/src/utils/__tests__/__snapshots__/handle-flags.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Object {
3838
- ALL_COMMANDS · (Umbrella Issue (test)) · test
3939
4040
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
41-
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
41+
and your site was automatically chosen as one of them. With your help, we'll then release them to everyone in the next minor release.
4242
4343
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
4444
@@ -88,7 +88,7 @@ Object {
8888
"message": "
8989
9090
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
91-
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
91+
and your site was automatically chosen as one of them. With your help, we'll then release them to everyone in the next minor release.
9292
9393
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
9494
@@ -142,7 +142,7 @@ Object {
142142
- ALL_COMMANDS · (Umbrella Issue (test)) · test
143143
144144
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
145-
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
145+
and your site was automatically chosen as one of them. With your help, we'll then release them to everyone in the next minor release.
146146
147147
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
148148
@@ -242,7 +242,7 @@ Object {
242242
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
243243
244244
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
245-
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
245+
and your site was automatically chosen as one of them. With your help, we'll then release them to everyone in the next minor release.
246246
247247
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
248248

packages/gatsby/src/utils/__tests__/handle-flags.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ describe(`handle flags`, () => {
205205
it(`removes flags people explicitly opt out of and ignores flags that don't pass semver`, () => {
206206
const response = handleFlags(
207207
activeFlags,
208-
{ PARTIAL_RELEASE: false, PARTIAL_RELEASE_ONLY_NEW_LODASH: false },
208+
{
209+
PARTIAL_RELEASE: false,
210+
PARTIAL_RELEASE_ONLY_NEW_LODASH: false,
211+
},
209212
`develop`
210213
)
211214
expect(response.enabledConfigFlags).toHaveLength(0)
@@ -231,4 +234,46 @@ describe(`handle flags`, () => {
231234
}
232235
`)
233236
})
237+
238+
it(`Prefers explicit opt-in over auto opt-in (for terminal message)`, () => {
239+
const response = handleFlags(
240+
activeFlags.concat([
241+
{
242+
name: `ALWAYS_OPT_IN`,
243+
env: `GATSBY_ALWAYS_OPT_IN`,
244+
command: `all`,
245+
description: `test`,
246+
umbrellaIssue: `test`,
247+
telemetryId: `test`,
248+
experimental: false,
249+
// this will always OPT IN
250+
testFitness: (): fitnessEnum => `OPT_IN`,
251+
},
252+
]),
253+
{
254+
ALWAYS_OPT_IN: true,
255+
DEV_SSR: true,
256+
PARTIAL_RELEASE: false,
257+
PARTIAL_RELEASE_ONLY_NEW_LODASH: false,
258+
},
259+
`develop`
260+
)
261+
262+
expect(response.message).not.toContain(`automatically enabled`)
263+
expect(response.message).toMatchInlineSnapshot(`
264+
"The following flags are active:
265+
- ALWAYS_OPT_IN · (Umbrella Issue (test)) · test
266+
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
267+
268+
There are 7 other flags available that you might be interested in:
269+
- FAST_DEV · Enable all experiments aimed at improving develop server start time
270+
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
271+
- ONLY_BUILDS · (Umbrella Issue (test)) · test
272+
- ALL_COMMANDS · (Umbrella Issue (test)) · test
273+
- YET_ANOTHER · (Umbrella Issue (test)) · test
274+
- PARTIAL_RELEASE · (Umbrella Issue (test)) · test
275+
- PARTIAL_RELEASE_ONLY_NEW_LODASH · (Umbrella Issue (test)) · test
276+
"
277+
`)
278+
})
234279
})

packages/gatsby/src/utils/handle-flags.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ const handleFlags = (
7070
availableFlags.forEach(flag => {
7171
const fitness = flag.testFitness(flag)
7272

73-
if (configFlags[flag.name] !== false && fitness === `OPT_IN`) {
73+
// if user didn't explicitly set a flag (either true or false)
74+
// and it qualifies for auto opt-in - add it to optedInFlags
75+
if (typeof configFlags[flag.name] === `undefined` && fitness === `OPT_IN`) {
7476
enabledConfigFlags.push(flag)
7577
optedInFlags.set(flag.name, flag)
7678
}
@@ -143,7 +145,7 @@ const handleFlags = (
143145
if (optedInFlags.size > 0) {
144146
message += `\n\n`
145147
message += `We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
146-
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
148+
and your site was automatically chosen as one of them. With your help, we'll then release them to everyone in the next minor release.
147149
148150
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
149151

0 commit comments

Comments
 (0)