Unverified Commit 7e95e300 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix: allow certain variable names in development (#33638)

Fixes #24570

A few variable names (listed https://github.com/vercel/next.js/issues/24570#issuecomment-828721019) were causing problems when using `next dev`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
parent 0d642f12
...@@ -17,6 +17,8 @@ declare const module: { ...@@ -17,6 +17,8 @@ declare const module: {
// This function gets unwrapped into global scope, which is why we don't invert // This function gets unwrapped into global scope, which is why we don't invert
// if-blocks. Also, you cannot use `return`. // if-blocks. Also, you cannot use `return`.
export default function () { export default function () {
// Wrapped in an IIFE to avoid polluting the global scope
;(function () {
// Legacy CSS implementations will `eval` browser code in a Node.js context // Legacy CSS implementations will `eval` browser code in a Node.js context
// to extract CSS. For backwards compatibility, we need to check we're in a // to extract CSS. For backwards compatibility, we need to check we're in a
// browser context before continuing. // browser context before continuing.
...@@ -80,4 +82,5 @@ export default function () { ...@@ -80,4 +82,5 @@ export default function () {
} }
} }
} }
})()
} }
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from './helpers'
describe('ReactRefreshModule', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {},
skipStart: true,
})
})
afterAll(() => next.destroy())
it('should allow any variable names', async () => {
const { session, cleanup } = await sandbox(next, new Map([]))
expect(await session.hasRedbox()).toBe(false)
const variables = [
'_a',
'_b',
'currentExports',
'prevExports',
'isNoLongerABoundary',
]
for await (const variable of variables) {
await session.patch(
'pages/index.js',
`import { default as ${variable} } from 'next/link'
export default function Page() {
return null
}`
)
expect(await session.hasRedbox()).toBe(false)
expect(next.cliOutput).not.toContain(
`'${variable}' has already been declared`
)
}
await cleanup()
})
})
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