Unverified Commit 48874f1a authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix missing dev option for the middleware SSR loader (#30639)

Currently the `dev` option isn't passed to the render function inside the middleware SSR loader. This PR fixes it with a test case. 

Fixes #30547.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] 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 c730f731
...@@ -141,6 +141,7 @@ export default function middlewareRSCLoader(this: any) { ...@@ -141,6 +141,7 @@ export default function middlewareRSCLoader(this: any) {
// locale: detectedLocale, // locale: detectedLocale,
// defaultLocale, // defaultLocale,
// domainLocales: i18n?.domains, // domainLocales: i18n?.domains,
dev: process.env.NODE_ENV !== 'production',
App, App,
Document, Document,
buildManifest, buildManifest,
......
import styles from './style.module.css'
export default function RedText({ children }) {
return <div className={styles.text}>{children}</div>
}
import '../styles.css'
function App({ Component, pageProps }) { function App({ Component, pageProps }) {
return <Component {...pageProps} /> return <Component {...pageProps} />
} }
......
// CSS modules can only be imported inside client components for now.
import RedText from '../components/red/index.client'
export default function CSSM() {
return (
<RedText>
<h1>This should be in red</h1>
</RedText>
)
}
export default function GlobalStyle() {
return (
<div>
<h1 id="red">This should be in red</h1>
</div>
)
}
export default function GlobalStyle() {
return (
<div>
<h1 id="red">This should be in red</h1>
</div>
)
}
/* eslint-env jest */
import webdriver from 'next-webdriver'
export default function (context) {
it('should include global styles under `concurrentFeatures: true`', async () => {
const browser = await webdriver(context.appPort, '/global-styles')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#red')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})
it('should include global styles with `serverComponents: true`', async () => {
const browser = await webdriver(context.appPort, '/global-styles-rsc')
const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#red')).color`
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})
// TODO: fix this test
// it.skip('should include css modules with `serverComponents: true`', async () => {
// const browser = await webdriver(context.appPort, '/css-modules')
// const currentColor = await browser.eval(
// `window.getComputedStyle(document.querySelector('h1')).color`
// )
// expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
// })
}
...@@ -13,6 +13,8 @@ import { ...@@ -13,6 +13,8 @@ import {
renderViaHTTP, renderViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
import css from './css'
const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')] const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')]
const appDir = join(__dirname, '../app') const appDir = join(__dirname, '../app')
const distDir = join(__dirname, '../app/.next') const distDir = join(__dirname, '../app/.next')
...@@ -88,12 +90,14 @@ describe('RSC prod', () => { ...@@ -88,12 +90,14 @@ describe('RSC prod', () => {
const content = JSON.parse( const content = JSON.parse(
await fs.readFile(middlewareManifestPath, 'utf8') await fs.readFile(middlewareManifestPath, 'utf8')
) )
expect(content.clientInfo).toEqual([ for (const item of [
['/', true], ['/', true],
['/next-api/image', true], ['/next-api/image', true],
['/next-api/link', true], ['/next-api/link', true],
['/routes/[dynamic]', true], ['/routes/[dynamic]', true],
]) ]) {
expect(content.clientInfo).toContainEqual(item)
}
}) })
runTests(context) runTests(context)
}) })
...@@ -111,6 +115,35 @@ describe('RSC dev', () => { ...@@ -111,6 +115,35 @@ describe('RSC dev', () => {
runTests(context) runTests(context)
}) })
describe('CSS prod', () => {
const context = { appDir }
beforeAll(async () => {
context.appPort = await findPort()
await nextBuild(context.appDir)
context.server = await nextStart(context.appDir, context.appPort)
})
afterAll(async () => {
await killApp(context.server)
})
css(context)
})
describe('CSS dev', () => {
const context = { appDir }
beforeAll(async () => {
context.appPort = await findPort()
context.server = await nextDev(context.appDir, context.appPort)
})
afterAll(async () => {
await killApp(context.server)
})
css(context)
})
async function runTests(context) { async function runTests(context) {
it('should render the correct html', async () => { it('should render the correct html', async () => {
const homeHTML = await renderViaHTTP(context.appPort, '/') const homeHTML = await renderViaHTTP(context.appPort, '/')
......
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