Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing dev option for the middleware SSR loader #30639

Merged
merged 6 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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)"`)
// })
}
31 changes: 31 additions & 0 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 @@ -111,6 +113,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