Unverified Commit f36ad4c8 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove experimental.pageEnv (#54789)

This experimental feature didn't pan out and was left in accidentally.
This PR removes it.
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 0e1c85ce
......@@ -358,22 +358,6 @@ export function getDefineEnv({
'global.GENTLY': JSON.stringify(false),
}
: undefined),
// stub process.env with proxy to warn a missing value is
// being accessed in development mode
...(config.experimental.pageEnv && dev
? {
'process.env': `
new Proxy(${isNodeServer ? 'process.env' : '{}'}, {
get(target, prop) {
if (typeof target[prop] === 'undefined') {
console.warn(\`An environment variable (\${prop}) that was not provided in the environment was accessed.\nSee more info here: https://nextjs.org/docs/messages/missing-env-value\`)
}
return target[prop]
}
})
`,
}
: {}),
}
}
......@@ -2720,7 +2704,6 @@ export default async function getBaseWebpackConfig(
serverActions: config.experimental.serverActions,
typedRoutes: config.experimental.typedRoutes,
basePath: config.basePath,
pageEnv: config.experimental.pageEnv,
excludeDefaultMomentLocales: config.excludeDefaultMomentLocales,
assetPrefix: config.assetPrefix,
disableOptimizedLoading,
......
......@@ -33,7 +33,6 @@ const supportedTurbopackNextConfigOptions = [
'experimental.proxyTimeout',
'experimental.isrFlushToDisk',
'experimental.workerThreads',
'experimenatl.pageEnv',
'experimental.caseSensitiveRoutes',
]
......
......@@ -384,9 +384,6 @@ const configSchema = {
outputFileTracingIncludes: {
type: 'object',
},
pageEnv: {
type: 'boolean',
},
proxyTimeout: {
minimum: 0,
type: 'number',
......
......@@ -175,7 +175,6 @@ export interface ExperimentalConfig {
proxyTimeout?: number
isrFlushToDisk?: boolean
workerThreads?: boolean
pageEnv?: boolean
// optimizeCss can be boolean or critters' option object
// Use Record<string, unknown> as critters doesn't export its Option type
// https://github.com/GoogleChromeLabs/critters/blob/a590c05f9197b656d2aeaae9369df2483c26b072/packages/critters/src/index.d.ts
......@@ -712,7 +711,6 @@ export const defaultConfig: NextConfig = {
sharedPool: true,
isrFlushToDisk: true,
workerThreads: false,
pageEnv: false,
proxyTimeout: undefined,
optimizeCss: false,
nextScriptWorkers: false,
......
import { PHASE_PRODUCTION_BUILD } from 'next/constants'
const { NODE_ENV } = process.env
const { NEXT_PHASE } = process.env
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN
if (NODE_ENV !== 'development' && NEXT_PHASE !== PHASE_PRODUCTION_BUILD) {
console.log('next start', SENTRY_DSN)
}
export default () => process.env.HELLO || 'hi'
module.exports = {
experimental: {
pageEnv: true,
},
}
export default () => {
console.log(process.env.I_SHOULD_BE_HERE)
return <p>hi there 👋</p>
}
export default (req, res) => {
console.log(process.env.where_is_it)
res.end('done')
}
export default () => {
return <p>hi there 👋</p>
}
export const getStaticProps = () => {
console.log(process.env.SECRET)
return {
props: {
hi: 'there',
},
}
}
export default () => {
return <p>hi there 👋</p>
}
export const getServerSideProps = () => {
console.log(process.env.SECRET)
return {
props: {
hi: 'there',
},
}
}
import dynamic from 'next/dynamic'
const Hello = dynamic(() => import('../components/hello'), { ssr: true })
export default () => {
// make sure we handle this syntax correctly
const { hi } = process.env
console.log(hi)
return (
<>
<p>hi there 👋</p>
<Hello />
</>
)
}
export default () => {
console.log(process.env.NEXT_PUBLIC_HI)
return <p>hi there 👋</p>
}
/* eslint-env jest */
import {
findPort,
killApp,
launchApp,
renderViaHTTP,
waitFor,
nextBuild,
nextStart,
} from 'next-test-utils'
import { join } from 'path'
import webdriver from 'next-webdriver'
const appDir = join(__dirname, '..')
let app
let stderr
let appPort
const buildWarning = (prop) =>
`An environment variable (${prop}) that was not provided in the environment was accessed`
const checkMissing = async (pathname, prop, shouldWarn = false) => {
stderr = ''
await renderViaHTTP(appPort, pathname)
await waitFor(1000)
if (shouldWarn) {
expect(stderr).toContain(buildWarning(prop))
} else {
expect(stderr).not.toContain(buildWarning(prop))
}
}
const checkMissingClient = async (pathname, prop, shouldWarn = false) => {
const browser = await webdriver(appPort, '/404')
await browser.eval(`(function() {
window.warnLogs = []
var origWarn = console.warn
console.warn = function() {
window.warnLogs.push(arguments[0])
origWarn.apply(this, arguments)
}
window.next.router.push("${pathname}")
})()`)
await waitFor(2000)
const logs = await browser.eval(`window.warnLogs`)
const warning = buildWarning(prop)
const hasWarn = logs.some((log) => log.includes(warning))
expect(hasWarn).toBe(shouldWarn)
await browser.close()
}
describe('process.env stubbing', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort, {
env: {
NEXT_PUBLIC_HI: 'hi',
I_SHOULD_BE_HERE: 'hello',
},
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(() => killApp(app))
describe('server side', () => {
it('should not show missing env value when its not missing public', async () => {
await checkMissing('/not-missing', 'NEXT_PUBLIC_HI')
})
it('should not show missing env value when its not missing runtime', async () => {
await checkMissing('/also-not-missing', 'I_SHOULD_BE_HERE')
})
it('should show missing env value when its missing normal', async () => {
await checkMissing('/missing', 'hi', true)
})
it('should show missing env value when its missing GSP', async () => {
await checkMissing('/missing-gsp', 'SECRET', true)
})
it('should show missing env value when its missing GSSP', async () => {
await checkMissing('/missing-gssp', 'SECRET', true)
})
it('should show missing env value when its missing API', async () => {
await checkMissing('/api/hi', 'where_is_it', true)
})
})
describe('client side', () => {
it('should not show missing env value when its not missing public', async () => {
await checkMissingClient('/not-missing', 'NEXT_PUBLIC_HI')
})
it('should show missing env value when its missing runtime', async () => {
await checkMissingClient('/also-not-missing', 'I_SHOULD_BE_HERE', true)
})
it('should show missing env value when its missing normal', async () => {
await checkMissingClient('/missing', 'hi', true)
})
})
})
describe('production mode', () => {
beforeAll(async () => {
const { code } = await nextBuild(appDir)
if (code !== 0) throw new Error(`build failed with code ${code}`)
appPort = await findPort()
app = await nextStart(appDir, appPort, {
onStderr(msg) {
stderr += msg || ''
},
})
})
afterAll(() => killApp(app))
describe('server side', () => {
it('should not show missing env value when its not missing public', async () => {
await checkMissing('/not-missing', 'NEXT_PUBLIC_HI')
})
it('should not show missing env value when its not missing runtime', async () => {
await checkMissing('/also-not-missing', 'I_SHOULD_BE_HERE')
})
it('should not show missing env value when its missing normal', async () => {
await checkMissing('/missing', 'hi')
})
it('should not show missing env value when its missing GSP', async () => {
await checkMissing('/missing-gsp', 'SECRET')
})
it('should not show missing env value when its missing GSSP', async () => {
await checkMissing('/missing-gssp', 'SECRET')
})
it('should not show missing env value when its missing API', async () => {
await checkMissing('/api/hi', 'where_is_it')
})
})
describe('client side', () => {
it('should not show missing env value when its not missing public', async () => {
await checkMissingClient('/not-missing', 'NEXT_PUBLIC_HI')
})
it('should not show missing env value when its missing runtime', async () => {
await checkMissingClient('/also-not-missing', 'I_SHOULD_BE_HERE')
})
it('should not show missing env value when its missing normal', async () => {
await checkMissingClient('/missing', 'hi')
})
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment