Skip to content

Commit 48874f1

Browse files
authoredOct 30, 2021
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`
1 parent c730f73 commit 48874f1

File tree

10 files changed

+100
-2
lines changed

10 files changed

+100
-2
lines changed
 

‎packages/next/build/webpack/loaders/next-middleware-ssr-loader/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default function middlewareRSCLoader(this: any) {
141141
// locale: detectedLocale,
142142
// defaultLocale,
143143
// domainLocales: i18n?.domains,
144+
dev: process.env.NODE_ENV !== 'production',
144145
App,
145146
Document,
146147
buildManifest,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import styles from './style.module.css'
2+
3+
export default function RedText({ children }) {
4+
return <div className={styles.text}>{children}</div>
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.text {
2+
color: red;
3+
}

‎test/integration/react-rsc-basic/app/pages/_app.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '../styles.css'
2+
13
function App({ Component, pageProps }) {
24
return <Component {...pageProps} />
35
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// CSS modules can only be imported inside client components for now.
2+
import RedText from '../components/red/index.client'
3+
4+
export default function CSSM() {
5+
return (
6+
<RedText>
7+
<h1>This should be in red</h1>
8+
</RedText>
9+
)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function GlobalStyle() {
2+
return (
3+
<div>
4+
<h1 id="red">This should be in red</h1>
5+
</div>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function GlobalStyle() {
2+
return (
3+
<div>
4+
<h1 id="red">This should be in red</h1>
5+
</div>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#red {
2+
color: red;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-env jest */
2+
import webdriver from 'next-webdriver'
3+
4+
export default function (context) {
5+
it('should include global styles under `concurrentFeatures: true`', async () => {
6+
const browser = await webdriver(context.appPort, '/global-styles')
7+
const currentColor = await browser.eval(
8+
`window.getComputedStyle(document.querySelector('#red')).color`
9+
)
10+
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
11+
})
12+
it('should include global styles with `serverComponents: true`', async () => {
13+
const browser = await webdriver(context.appPort, '/global-styles-rsc')
14+
const currentColor = await browser.eval(
15+
`window.getComputedStyle(document.querySelector('#red')).color`
16+
)
17+
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
18+
})
19+
// TODO: fix this test
20+
// it.skip('should include css modules with `serverComponents: true`', async () => {
21+
// const browser = await webdriver(context.appPort, '/css-modules')
22+
// const currentColor = await browser.eval(
23+
// `window.getComputedStyle(document.querySelector('h1')).color`
24+
// )
25+
// expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
26+
// })
27+
}

‎test/integration/react-rsc-basic/test/index.test.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
renderViaHTTP,
1414
} from 'next-test-utils'
1515

16+
import css from './css'
17+
1618
const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')]
1719
const appDir = join(__dirname, '../app')
1820
const distDir = join(__dirname, '../app/.next')
@@ -88,12 +90,14 @@ describe('RSC prod', () => {
8890
const content = JSON.parse(
8991
await fs.readFile(middlewareManifestPath, 'utf8')
9092
)
91-
expect(content.clientInfo).toEqual([
93+
for (const item of [
9294
['/', true],
9395
['/next-api/image', true],
9496
['/next-api/link', true],
9597
['/routes/[dynamic]', true],
96-
])
98+
]) {
99+
expect(content.clientInfo).toContainEqual(item)
100+
}
97101
})
98102
runTests(context)
99103
})
@@ -111,6 +115,35 @@ describe('RSC dev', () => {
111115
runTests(context)
112116
})
113117

118+
describe('CSS prod', () => {
119+
const context = { appDir }
120+
121+
beforeAll(async () => {
122+
context.appPort = await findPort()
123+
await nextBuild(context.appDir)
124+
context.server = await nextStart(context.appDir, context.appPort)
125+
})
126+
afterAll(async () => {
127+
await killApp(context.server)
128+
})
129+
130+
css(context)
131+
})
132+
133+
describe('CSS dev', () => {
134+
const context = { appDir }
135+
136+
beforeAll(async () => {
137+
context.appPort = await findPort()
138+
context.server = await nextDev(context.appDir, context.appPort)
139+
})
140+
afterAll(async () => {
141+
await killApp(context.server)
142+
})
143+
144+
css(context)
145+
})
146+
114147
async function runTests(context) {
115148
it('should render the correct html', async () => {
116149
const homeHTML = await renderViaHTTP(context.appPort, '/')

0 commit comments

Comments
 (0)
Please sign in to comment.