Unverified Commit bc3ab3ce authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move swcMinify out of experimental (#29810)

parent b31b4923
...@@ -490,6 +490,10 @@ ...@@ -490,6 +490,10 @@
{ {
"title": "swc-disabled", "title": "swc-disabled",
"path": "/errors/swc-disabled.md" "path": "/errors/swc-disabled.md"
},
{
"title": "swc-minify-enabled",
"path": "/errors/swc-minify-enabled.md"
} }
] ]
} }
......
# SWC minify enabled
#### Why This Message Occurred
The application has enabled `swcMinify` in `next.config.js`. By opting in minification will happen using the [SWC](https://swc.rs) minifier instead of Terser. This new minifier is 7x faster than Terser with comparable output. We're actively working on optimizing the output size and minification speed further.
If you have feedback about the minification, please provide it on [the feedback thread](https://github.com/vercel/next.js/discussions/30237).
...@@ -299,7 +299,7 @@ export default async function getBaseWebpackConfig( ...@@ -299,7 +299,7 @@ export default async function getBaseWebpackConfig(
const distDir = path.join(dir, config.distDir) const distDir = path.join(dir, config.distDir)
const useSWCLoader = config.experimental.swcLoader && !babelConfigFile const useSWCLoader = !babelConfigFile
if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) { if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
Log.warn( Log.warn(
`Disabled SWC because of custom Babel configuration "${path.relative( `Disabled SWC because of custom Babel configuration "${path.relative(
...@@ -942,7 +942,7 @@ export default async function getBaseWebpackConfig( ...@@ -942,7 +942,7 @@ export default async function getBaseWebpackConfig(
new TerserPlugin({ new TerserPlugin({
cacheDir: path.join(distDir, 'cache', 'next-minifier'), cacheDir: path.join(distDir, 'cache', 'next-minifier'),
parallel: config.experimental.cpus, parallel: config.experimental.cpus,
swcMinify: config.experimental.swcMinify, swcMinify: config.swcMinify,
terserOptions, terserOptions,
}).apply(compiler) }).apply(compiler)
}, },
...@@ -1411,8 +1411,8 @@ export default async function getBaseWebpackConfig( ...@@ -1411,8 +1411,8 @@ export default async function getBaseWebpackConfig(
hasRewrites, hasRewrites,
reactRoot: config.experimental.reactRoot, reactRoot: config.experimental.reactRoot,
concurrentFeatures: config.experimental.concurrentFeatures, concurrentFeatures: config.experimental.concurrentFeatures,
swcMinify: config.experimental.swcMinify, swcMinify: config.swcMinify,
swcLoader: config.experimental.swcLoader, swcLoader: useSWCLoader,
}) })
const cache: any = { const cache: any = {
......
...@@ -118,9 +118,9 @@ export type NextConfig = { [key: string]: any } & { ...@@ -118,9 +118,9 @@ export type NextConfig = { [key: string]: any } & {
} }
staticPageGenerationTimeout?: number staticPageGenerationTimeout?: number
crossOrigin?: false | 'anonymous' | 'use-credentials' crossOrigin?: false | 'anonymous' | 'use-credentials'
swcMinify?: boolean
experimental?: { experimental?: {
swcMinify?: boolean swcMinify?: boolean
swcLoader?: boolean
cpus?: number cpus?: number
sharedPool?: boolean sharedPool?: boolean
plugins?: boolean plugins?: boolean
...@@ -202,9 +202,8 @@ export const defaultConfig: NextConfig = { ...@@ -202,9 +202,8 @@ export const defaultConfig: NextConfig = {
keepAlive: true, keepAlive: true,
}, },
staticPageGenerationTimeout: 60, staticPageGenerationTimeout: 60,
swcMinify: false,
experimental: { experimental: {
swcLoader: true,
swcMinify: false,
cpus: Math.max( cpus: Math.max(
1, 1,
(Number(process.env.CIRCLE_NODE_TOTAL) || (Number(process.env.CIRCLE_NODE_TOTAL) ||
......
...@@ -358,6 +358,19 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -358,6 +358,19 @@ function assignDefaults(userConfig: { [key: string]: any }) {
) )
} }
if (result.experimental && 'swcMinify' in (result.experimental as any)) {
Log.warn(
`\`swcMinify\` has been moved out of \`experimental\`. Please update your ${configFileName} file accordingly.`
)
result.swcMinify = (result.experimental as any).swcMinify
}
if (result.swcMinify) {
Log.warn(
'SWC minify beta enabled. nextjs.org/docs/messages/swc-minify-enabled'
)
}
if (result.experimental && 'nftTracing' in (result.experimental as any)) { if (result.experimental && 'nftTracing' in (result.experimental as any)) {
// TODO: remove this warning and assignment when we leave experimental phase // TODO: remove this warning and assignment when we leave experimental phase
Log.warn( Log.warn(
......
...@@ -133,12 +133,12 @@ module.exports = { ...@@ -133,12 +133,12 @@ module.exports = {
content: ` content: `
module.exports = { module.exports = {
generateBuildId: () => 'BUILD_ID', generateBuildId: () => 'BUILD_ID',
swcMinify: ${
// TODO: remove after stable release > 11.1.2
process.env.STATS_IS_RELEASE ? 'false' : 'true'
},
experimental: { experimental: {
swcLoader: true, swcLoader: true,
swcMinify: ${
// TODO: remove after stable release > 11.1.2
process.env.STATS_IS_RELEASE ? 'false' : 'true'
},
}, },
webpack(config) { webpack(config) {
config.optimization.minimize = false config.optimization.minimize = false
...@@ -160,12 +160,13 @@ module.exports = { ...@@ -160,12 +160,13 @@ module.exports = {
path: 'next.config.js', path: 'next.config.js',
content: ` content: `
module.exports = { module.exports = {
swcMinify: ${
// TODO: remove after stable release > 11.1.2
process.env.STATS_IS_RELEASE ? 'false' : 'true'
},
experimental: { experimental: {
swcLoader: true, swcLoader: true,
swcMinify: ${
// TODO: remove after stable release > 11.1.2
process.env.STATS_IS_RELEASE ? 'false' : 'true'
},
}, },
generateBuildId: () => 'BUILD_ID' generateBuildId: () => 'BUILD_ID'
} }
......
{
"presets": ["next/babel"]
}
...@@ -5,7 +5,4 @@ module.exports = { ...@@ -5,7 +5,4 @@ module.exports = {
config.experiments.topLevelAwait = true config.experiments.topLevelAwait = true
return config return config
}, },
experimental: {
swcLoader: false,
},
} }
module.exports = {
experimental: {
swcLoader: false,
},
}
import styles from './with-css-1.module.css'
export default () => <p className={styles.content}>With CSS 1</p>
import styles from './with-css-2.module.css'
export default () => <p className={styles.content}>With CSS 2</p>
import styles from './with-css-3.module.css'
export default () => <p className={styles.content}>With CSS 3</p>
import styles from './with-css.module.css'
import styles2 from './with-css-2.module.css'
export default () => (
<div className={styles.content}>
<p className={styles2.text}>With CSS</p>
</div>
)
import styles2 from './with-css-2.module.css'
export default () => <p className={styles2.text}>With CSS</p>
import styles from './with-css.module.css'
import Nested from './Nested'
export default () => (
<div className={styles.content}>
<Nested />
</div>
)
import styles from './with-css-2.module.css'
import stylesShared from './with-css-shared.module.css'
export default () => (
<div className={styles.content}>
<p className={stylesShared.test}>With CSS</p>
</div>
)
import styles from './with-css.module.css'
import stylesShared from './with-css-shared.module.css'
export default () => (
<div className={styles.content}>
<p className={stylesShared.test}>With CSS</p>
</div>
)
import styles from './with-css.module.css'
export default () => (
<p id="with-css" className={styles.content}>
With CSS
</p>
)
import React from 'react'
import PropTypes from 'prop-types'
export default class extends React.Component {
static contextTypes = {
data: PropTypes.object,
}
render() {
const { data } = this.context
return <div>{data.title}</div>
}
}
export default () => <p>Hello World 1</p>
export default () => <p>Hello World 2</p>
<?xml version="1.0" encoding="UTF-8"?>
<svg width="114px" height="100px" viewBox="0 0 114 100" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.2 (57519) - http://www.bohemiancoding.com/sketch -->
<title>Logotype - Black</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="100.929941%" y1="181.283245%" x2="41.7687834%" y2="100%" id="linearGradient-1">
<stop stop-color="#FFFFFF" offset="0%"></stop>
<stop stop-color="#000000" offset="100%"></stop>
</linearGradient>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Black-Triangle" transform="translate(-293.000000, -150.000000)" fill="url(#linearGradient-1)">
<polygon id="Logotype---Black" points="350 150 407 250 293 250"></polygon>
</g>
</g>
</svg>
import styles from './logo.module.css'
export default function Logo() {
return <div className={styles.logo}></div>
}
import React from 'react'
export default class Welcome extends React.Component {
state = { name: null }
componentDidMount() {
const { name } = this.props
this.setState({ name })
}
render() {
const { name } = this.state
if (!name) return null
return <p>Welcome, {name}</p>
}
}
// intervals/open connections shouldn't block build from exiting
setInterval(() => {}, 250)
module.exports = {
swcMinify: true,
experimental: {
outputFileTracing: true,
},
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
rewrites() {
// add a rewrite so the code isn't dead-code eliminated
return [
{
source: '/some-rewrite',
destination: '/',
},
]
},
redirects() {
return [
{
source: '/redirect/me/to-about/:lang',
destination: '/:lang/about',
permanent: false,
},
{
source: '/nonexistent',
destination: '/about',
permanent: false,
},
{
source: '/shadowed-page',
destination: '/about',
permanent: false,
},
{
source: '/redirect-query-test/:path',
destination: '/about?foo=:path',
permanent: false,
},
]
},
}
export default () => <div className="about-page">About Page</div>
export default () => 'hi'
export const config = { amp: 'hybrid' }
export default () => 'hi'
export const config = { amp: true }
import Link from 'next/link'
export default () => (
<div>
<Link href="/">
<a>Index Page</a>
</Link>
<p>Another</p>
</div>
)
export default ({ query }, res) => {
res.status(200).json(query)
}
export default (req, res) => {
res.end('API hello works')
}
export default (req, res) => {
res.end('API index works')
}
export default () => {
if (typeof window !== 'undefined') {
window.didRender = true
}
return (
<>
<script
dangerouslySetInnerHTML={{ __html: 'window.Promise = undefined' }}
/>
</>
)
}
import Link from 'next/link'
import Error from 'next/error'
export default function Page(props) {
return (
<>
<Error title="something went wrong (on purpose)" />
<Link href="/">
<a>to home</a>
</Link>
</>
)
}
import Link from 'next/link'
import { Component } from 'react'
import Router from 'next/router'
let counter = 0
export default class extends Component {
increase() {
counter++
this.forceUpdate()
}
visitQueryStringPage() {
const href = { pathname: '/nav/querystring', query: { id: 10 } }
const as = { pathname: '/nav/querystring/10', hash: '10' }
Router.push(href, as)
}
render() {
return (
<div id="counter-page">
<Link href="/no-such-page">
<a id="no-such-page">No Such Page</a>
</Link>
<br />
<Link href="/no-such-page" prefetch>
<a id="no-such-page-prefetch">No Such Page (with prefetch)</a>
</Link>
<p>This is the home.</p>
<div id="counter">Counter: {counter}</div>
<button id="increase" onClick={() => this.increase()}>
Increase
</button>
</div>
)
}
}
import Link from 'next/link'
const Page = ({ from }) => (
<div>
<p>{from}</p>
<Link href="/css-modules">
<a>Page with CSS</a>
</Link>
</div>
)
Page.getInitialProps = () => {
return { from: typeof window === 'undefined' ? 'server' : 'client' }
}
export default Page
import Logo from '../components/logo'
export default () => (
<div>
<Logo />
<input />
</div>
)
import Link from 'next/link'
export default function IndexPage() {
return (
<div>
<Link href="/about" prefetch>
<a>To About Page</a>
</Link>
</div>
)
}
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/dynamic-css/with-css'))
export default Hello
import Link from 'next/link'
export default () => (
<div>
<Link href="/dynamic/no-chunk">
<a>No Chunk</a>
</Link>
</div>
)
import dynamic from 'next/dynamic'
const Component = dynamic(
import('../../components/dynamic-css/many-modules/with-css')
)
export default Component
import dynamic from 'next/dynamic'
const First = dynamic(
import('../../components/dynamic-css/many-imports/with-css-1')
)
const Second = dynamic(
import('../../components/dynamic-css/many-imports/with-css-2')
)
const Third = dynamic(
import('../../components/dynamic-css/many-imports/with-css-3')
)
export default function Page() {
return (
<div>
<First />
<Second />
<Third />
</div>
)
}
import dynamic from 'next/dynamic'
const Component = dynamic(
import('../../components/dynamic-css/nested/with-css')
)
export default Component
import dynamic from 'next/dynamic'
import Welcome from '../../components/welcome'
const Welcome2 = dynamic(import('../../components/welcome'))
export default () => (
<div>
<Welcome name="normal" />
<Welcome2 name="dynamic" />
</div>
)
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/dynamic-css/no-css'))
export default Hello
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'), {
ssr: false,
loading: () => <p>LOADING</p>,
})
export default Hello
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'), { ssr: false })
export default Hello
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/dynamic-css/with-css'))
export default function PageChange1() {
return (
<div>
PageChange1
<Hello />
</div>
)
}
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/dynamic-css/with-css'))
export default function PageChange2() {
return (
<div>
PageChange2
<Hello />
</div>
)
}
import dynamic from 'next/dynamic'
const First = dynamic(
import('../../components/dynamic-css/shared-css-module/with-css')
)
const Second = dynamic(
import('../../components/dynamic-css/shared-css-module/with-css-2')
)
export default function Page() {
return (
<div>
<First />
<Second />
</div>
)
}
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'), { ssr: true })
export default Hello
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello1'))
export default Hello
import React from 'react'
export default class ErrorInRenderPage extends React.Component {
render() {
if (typeof window !== 'undefined') {
const error = new Error('An Expected error occurred')
// This will be extracted by getInitialProps in the _error page,
// which will result in a different error message being rendered.
error.statusCode = 404
throw error
}
return <div />
}
}
import React from 'react'
export default class ErrorInRenderPage extends React.Component {
render() {
if (typeof window !== 'undefined') {
throw new Error('An Expected error occurred')
}
return <div />
}
}
import React from 'react'
export default class ErrorInRenderPage extends React.Component {
static async getInitialProps() {
return {}
}
// eslint-disable-next-line react/require-render-return
render() {
throw new Error('An Expected error occurred')
}
}
const Page = ({ from }) => (
<div>
<p>{from}</p>
<a href="https://google.com">External link</a>
</div>
)
Page.getInitialProps = () => {
return { from: typeof window === 'undefined' ? 'server' : 'client' }
}
export default Page
import React, { Component } from 'react'
export default class extends Component {
static getInitialProps({ res }) {
res.end('hi')
}
render() {
return <div>hi</div>
}
}
export async function getServerSideProps() {
return {
props: {
myDynamicProp: 'hello world',
},
}
}
export default function FullyDynamic({ myDynamicProp }) {
return <h1>{myDynamicProp}</h1>
}
export async function getStaticProps() {
return {
props: {
myStaticProp: 'hello world',
},
}
}
export default function FullyStatic({ myStaticProp }) {
return <h1>{myStaticProp}</h1>
}
import Link from 'next/link'
if (typeof window === 'undefined') {
import('nanoid').then((mod) => console.log(mod.nanoid()))
}
export default () => (
<div>
<Link href="/about">
<a>About Page</a>
</Link>
<p className="index-page">Hello World</p>
</div>
)
import { useRouter } from 'next/router'
export default function Page() {
return <p>hello {useRouter().query.slug}</p>
}
export const getServerSideProps = () => {
return {
props: {
hello: 'world',
},
}
}
import Head from 'next/head'
export default () => {
return (
<div>
Hello
<Head>
<script
dangerouslySetInnerHTML={{
__html: `performance.mark('custom-mark')`,
}}
/>
</Head>
</div>
)
}
import Link from 'next/link'
// Leave below import, testing that importing "next"
// doesn't stall the build
// eslint-disable-next-line no-unused-vars
import next from 'next'
export default () => (
<div>
<Link href="/about">
<a>About Page</a>
</Link>
<p className="index-page">Hello World</p>
</div>
)
import { Writable } from 'stream'
import path from 'path'
import crypto from 'crypto'
import { Buffer } from 'buffer'
import vm from 'vm'
import { useEffect, useState } from 'react'
export default function NodeBrowserPolyfillPage() {
const [state, setState] = useState({})
useEffect(() => {
let closedStream = false
const writable = new Writable({
write(_chunk, _encoding, callback) {
callback()
},
})
writable.on('finish', () => {
closedStream = true
})
writable.end()
setState({
path: path.join('/hello/world', 'test.txt'),
hash: crypto.createHash('sha256').update('hello world').digest('hex'),
buffer: Buffer.from('hello world').toString('utf8'),
vm: vm.runInNewContext('a + 5', { a: 100 }),
stream: closedStream,
})
}, [])
useEffect(() => {
if (state.vm) {
window.didRender = true
}
}, [state])
return (
<>
<div
id="node-browser-polyfills"
dangerouslySetInnerHTML={{ __html: JSON.stringify(state) }}
></div>
</>
)
}
import Link from 'next/link'
export default () => {
return (
<div>
<ul>
<li>
<Link href="/" prefetch>
<a id="prefetch-1">index</a>
</Link>
</li>
<li>
<Link href="/process-env" prefetch>
<a id="prefetch-2">process env</a>
</Link>
</li>
<li>
<Link href="/counter" prefetch>
<a id="prefetch-3">counter</a>
</Link>
</li>
<li>
<Link href="/about" prefetch>
<a id="prefetch-4">about</a>
</Link>
</li>
</ul>
</div>
)
}
if (process.browser) {
global.__THIS_SHOULD_ONLY_BE_DEFINED_IN_BROWSER_CONTEXT__ = true
}
if (!process.browser) {
global.__THIS_SHOULD_ONLY_BE_DEFINED_IN_SERVER_CONTEXT__ = true
}
const ProcessEnv = () => <div id="node-env">{process.env.NODE_ENV}</div>
ProcessEnv.getInitialProps = () => ({})
export default ProcessEnv
import { withRouter } from 'next/router'
const Page = ({ router: { query } }) => (
<>
<p id={'q' + query.id}>{query.id}</p>
<a id="first" href="/query?id=1">
Go to ?id=1
</a>
<a id="second" href="/query?id=2">
Go to ?id=2
</a>
</>
)
Page.getInitialProps = () => ({})
export default withRouter(Page)
import * as React from 'react'
const Home = () => {
if (typeof window !== 'undefined') {
window.didRender = true
}
React.useEffect(() => {
// If this script is loaded before the polyfills it will
// still fail
const el = document.createElement('script')
el.src = '/regexp-test.js'
document.querySelector('body').appendChild(el)
}, [])
return (
<>
<p>hi</p>
</>
)
}
export default Home
import getConfig from 'next/config'
const page = () => {
const { publicRuntimeConfig, serverRuntimeConfig } = getConfig()
return (
<>
{publicRuntimeConfig && <p>found public config</p>}
{serverRuntimeConfig && <p>found server config</p>}
</>
)
}
page.getInitialProps = () => ({})
export default page
export function getServerSideProps() {
throw new Error('oops!')
}
export default function ShadowedPage() {
return <div id="shadowed-page">Not routable!</div>
}
import { useAmp } from 'next/amp'
if (typeof window !== 'undefined') {
window.addEventListener('error', () => {
document.querySelector('p').innerText('error')
})
}
export const config = { amp: 'hybrid' }
export default () => <p>{useAmp() ? 'AMP' : 'Not AMP'}</p>
import Image from 'next/image'
import logo from '../public/vercel.png'
export default () => (
<div>
<p>Static Image</p>
<Image src={logo} placeholder="blur" id="static-image" />
</div>
)
import React from 'react'
import Image from 'next/image'
const Page = () => {
return (
<div>
<h1>SVG with a script tag attempting XSS</h1>
<Image id="img" src="/xss.svg" width="100" height="100" />
<p id="msg">safe</p>
</div>
)
}
export default Page
import Link from 'next/link'
export default function ToNonexistent() {
return (
<div id="blackhole-page">
<Link href="/nonexistent">
<a id="to-nonexistent-page">Nonexistent Page</a>
</Link>
</div>
)
}
import Link from 'next/link'
export default function ToShadowed() {
return (
<div id="shadowed-page-gateway">
<Link href="/shadowed-page">
<a id="to-shadowed-page">Shadowed Page</a>
</Link>
</div>
)
}
import Head from 'next/head'
export default () => (
<>
<Head>
<title>hello from title</title>
</Head>
<p id="with-title">hi</p>
</>
)
// Note: this needs to be loaded via script tag
// or node_modules to test correctly otherwise babel
// will transform it properly and it's not longer
// testing the correct thing
var str1 = 'table football'
var regex1 = new RegExp('foo', 'y') // sticky
regex1.lastIndex = 6
window.isSticky = regex1.sticky // Expected: true
window.isMatch1 = regex1.test(str1) // Expected: true
window.isMatch2 = regex1.test(str1) // Expected: false
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XSS</title>
</head>
<body>
<p id="msg">safe</p>
<script>document.getElementById('msg').textContent='hacked'</script>
</body>
</html>
/* eslint-env jest */
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import { check } from 'next-test-utils'
// These tests are similar to ../../basic/test/dynamic.js
export default (context, render) => {
async function get$(path, query) {
const html = await render(path, query)
return cheerio.load(html)
}
describe('Dynamic import', () => {
describe('default behavior', () => {
it('should render dynamic import components', async () => {
const $ = await get$('/dynamic/ssr')
expect($('body').text()).toMatch(/Hello World 1/)
})
it('should render one dynamically imported component and load its css files', async () => {
const $ = await get$('/dynamic/css')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(1)
})
it('should render three dynamically imported components and load their css files', async () => {
const $ = await get$('/dynamic/many-dynamic-css')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(3)
})
it('should bundle two css modules for one dynamically imported component into one css file', async () => {
const $ = await get$('/dynamic/many-css-modules')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(1)
})
it('should bundle two css modules for nested components into one css file', async () => {
const $ = await get$('/dynamic/nested-css')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(1)
})
it('should not remove css styles for same css file between page transitions', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/pagechange1')
await check(() => browser.elementByCss('body').text(), /PageChange1/)
const firstElement = await browser.elementById('with-css')
const css1 = await firstElement.getComputedCss('display')
expect(css1).toBe('flex')
await browser.eval(function () {
window.next.router.push('/dynamic/pagechange2')
})
await check(() => browser.elementByCss('body').text(), /PageChange2/)
const secondElement = await browser.elementById('with-css')
const css2 = await secondElement.getComputedCss('display')
expect(css2).toBe(css1)
} finally {
if (browser) {
await browser.close()
}
}
})
// It seem to be abnormal, dynamic CSS modules are completely self-sufficient, so shared styles are copied across files
it('should output two css files even in case of three css module files while one is shared across files', async () => {
const $ = await get$('/dynamic/shared-css-module')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(2)
})
it('should render one dynamically imported component without any css files', async () => {
const $ = await get$('/dynamic/no-css')
const cssFiles = $('link[rel=stylesheet]')
expect(cssFiles.length).toBe(0)
})
it('should render even there are no physical chunk exists', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/no-chunk')
await check(
() => browser.elementByCss('body').text(),
/Welcome, normal/
)
await check(
() => browser.elementByCss('body').text(),
/Welcome, dynamic/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
describe('ssr:false option', () => {
it('should not render loading on the server side', async () => {
const $ = await get$('/dynamic/no-ssr')
expect($('body').text()).not.toMatch('loading...')
})
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/no-ssr')
await check(
() => browser.elementByCss('body').text(),
/Hello World 1/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
describe('ssr:true option', () => {
it('should render the component on the server side', async () => {
const $ = await get$('/dynamic/ssr-true')
expect($('p').text()).toBe('Hello World 1')
})
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/dynamic/ssr-true')
await check(
() => browser.elementByCss('body').text(),
/Hello World 1/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
describe('custom loading', () => {
it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => {
const $ = await get$('/dynamic/no-ssr-custom-loading')
expect($('p').text()).toBe('LOADING')
})
it('should render the component on client side', async () => {
let browser
try {
browser = await webdriver(
context.appPort,
'/dynamic/no-ssr-custom-loading'
)
await check(
() => browser.elementByCss('body').text(),
/Hello World 1/
)
} finally {
if (browser) {
await browser.close()
}
}
})
})
})
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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