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 1 commit
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;
}
94 changes: 94 additions & 0 deletions test/integration/react-rsc-basic/test/css.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* eslint-env jest */
shuding marked this conversation as resolved.
Show resolved Hide resolved

import { join } from 'path'
import webdriver from 'next-webdriver'

import {
findPort,
killApp,
launchApp,
nextBuild as _nextBuild,
nextStart as _nextStart,
renderViaHTTP,
} from 'next-test-utils'

const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')]
const appDir = join(__dirname, '../app')
const distDir = join(__dirname, '../app/.next')

async function nextBuild(dir) {
shuding marked this conversation as resolved.
Show resolved Hide resolved
return await _nextBuild(dir, [], {
stdout: true,
stderr: true,
nodeArgs,
})
}

async function nextStart(dir, port) {
return await _nextStart(dir, port, {
stdout: true,
stderr: true,
nodeArgs,
})
}

async function nextDev(dir, port) {
return await launchApp(dir, port, {
stdout: true,
stderr: true,
nodeArgs,
})
}

describe('CSS import - 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)
})

runTests(context)
})

describe('CSS import - dev', () => {
const context = { appDir }

beforeAll(async () => {
context.appPort = await findPort()
context.server = await nextDev(context.appDir, context.appPort)
})
afterAll(async () => {
await killApp(context.server)
})
runTests(context)
})

async function runTests(context) {
shuding marked this conversation as resolved.
Show resolved Hide resolved
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)"`)
// })
}