Skip to content

Commit

Permalink
Fix missing dev option for the middleware SSR loader (#30639)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
shuding committed Oct 30, 2021
1 parent c730f73 commit 48874f1
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default function middlewareRSCLoader(this: any) {
// locale: detectedLocale,
// defaultLocale,
// domainLocales: i18n?.domains,
dev: process.env.NODE_ENV !== 'production',
App,
Document,
buildManifest,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from './style.module.css'

export default function RedText({ children }) {
return <div className={styles.text}>{children}</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text {
color: red;
}
2 changes: 2 additions & 0 deletions test/integration/react-rsc-basic/app/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../styles.css'

function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
Expand Down
10 changes: 10 additions & 0 deletions test/integration/react-rsc-basic/app/pages/css-modules.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function GlobalStyle() {
return (
<div>
<h1 id="red">This should be in red</h1>
</div>
)
}
7 changes: 7 additions & 0 deletions test/integration/react-rsc-basic/app/pages/global-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function GlobalStyle() {
return (
<div>
<h1 id="red">This should be in red</h1>
</div>
)
}
3 changes: 3 additions & 0 deletions test/integration/react-rsc-basic/app/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#red {
color: red;
}
27 changes: 27 additions & 0 deletions test/integration/react-rsc-basic/test/css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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)"`)
// })
}
37 changes: 35 additions & 2 deletions test/integration/react-rsc-basic/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
renderViaHTTP,
} from 'next-test-utils'

import css from './css'

const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')]
const appDir = join(__dirname, '../app')
const distDir = join(__dirname, '../app/.next')
Expand Down Expand Up @@ -88,12 +90,14 @@ describe('RSC prod', () => {
const content = JSON.parse(
await fs.readFile(middlewareManifestPath, 'utf8')
)
expect(content.clientInfo).toEqual([
for (const item of [
['/', true],
['/next-api/image', true],
['/next-api/link', true],
['/routes/[dynamic]', true],
])
]) {
expect(content.clientInfo).toContainEqual(item)
}
})
runTests(context)
})
Expand All @@ -111,6 +115,35 @@ describe('RSC dev', () => {
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) {
it('should render the correct html', async () => {
const homeHTML = await renderViaHTTP(context.appPort, '/')
Expand Down

0 comments on commit 48874f1

Please sign in to comment.