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

Remove deprecated features (#25446)

* Remove deprecated features

In the next major version we'll want to merge this PR that removes some of the long-time deprecated features, it'll have a positive effect on bundle size.

* Update tests

* Update tests

* Change unsized to layout=fill in test

* Update sizes

* Update rotation test

* Update size limit test

* Update test

* Update test

* Update test
parent d27cbf00
...@@ -4,6 +4,38 @@ description: Learn how to upgrade Next.js. ...@@ -4,6 +4,38 @@ description: Learn how to upgrade Next.js.
# Upgrade Guide # Upgrade Guide
## Upgrading from version 10 to 11
### Remove `super.componentDidCatch()` from `pages/_app.js`
The `next/app` component's `componentDidCatch` has been deprecated since Next.js 9 as it's no longer needed and has since been a no-op, in Next.js 11 it has been removed.
If your `pages/_app.js` has a custom `componentDidCatch` method you can remove `super.componentDidCatch` as it is no longer needed.
### Remove `Container` from `pages/_app.js`
This export has been deprecated since Next.js 9 as it's no longer needed and has since been a no-op with a warning during development. In Next.js 11 it has been removed.
If your `pages/_app.js` imports `Container` from `next/app` you can remove `Container` as it has been removed. Learn more in [the documentation](https://nextjs.org/docs/messages/app-container-deprecated).
### Remove `props.url` usage from page components
This property has been deprecated since Next.js 4 and has since shown a warning during development. With the introduction of `getStaticProps` / `getServerSideProps` these methods already disallowed usage of `props.url`. In Next.js 11 it has been removed completely.
You can learn more in [the documentation](https://nextjs.org/docs/messages/url-deprecated).
### Remove `unsized` property on `next/image`
The `unsized` property on `next/image` was deprecated in Next.js 10.0.1. You can use `layout="fill"` instead. In Next.js 11 `unsized` was removed.
### Remove `modules` property on `next/dynamic`
The `modules` and `render` option for `next/dynamic` have been deprecated since Next.js 9.5 showing a warning that it has been deprecated. This was done in order to make `next/dynamic` close to `React.lazy` in API surface. In Next.js 11 the `modules` and `render` options have been removed.
This option hasn't been mentioned in the documentation since Next.js 8 so it's less likely that your application is using it.
If you application does use `modules` and `render` you can refer to [the documentation](https://nextjs.org/docs/messages/next-dynamic-modules).
## React 16 to 17 ## React 16 to 17
React 17 introduced a new [JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) that brings a long-time Next.js feature to the wider React ecosystem: Not having to `import React from 'react'` when using JSX. When using React 17 Next.js will automatically use the new transform. This transform does not make the `React` variable global, which was an unintended side-effect of the previous Next.js implementation. A [codemod is available](/docs/advanced-features/codemods.md#add-missing-react-import) to automatically fix cases where you accidentally used `React` without importing it. React 17 introduced a new [JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) that brings a long-time Next.js feature to the wider React ecosystem: Not having to `import React from 'react'` when using JSX. When using React 17 Next.js will automatically use the new transform. This transform does not make the `React` variable global, which was an unintended side-effect of the previous Next.js implementation. A [codemod is available](/docs/advanced-features/codemods.md#add-missing-react-import) to automatically fix cases where you accidentally used `React` without importing it.
......
...@@ -62,12 +62,6 @@ export type ImageProps = Omit< ...@@ -62,12 +62,6 @@ export type ImageProps = Omit<
objectFit?: ImgElementStyle['objectFit'] objectFit?: ImgElementStyle['objectFit']
objectPosition?: ImgElementStyle['objectPosition'] objectPosition?: ImgElementStyle['objectPosition']
} & ( } & (
| {
width?: never
height?: never
/** @deprecated Use `layout="fill"` instead */
unsized: true
}
| { width?: never; height?: never; layout: 'fill' } | { width?: never; height?: never; layout: 'fill' }
| { | {
width: number | string width: number | string
...@@ -260,12 +254,7 @@ export default function Image({ ...@@ -260,12 +254,7 @@ export default function Image({
}: ImageProps) { }: ImageProps) {
let rest: Partial<ImageProps> = all let rest: Partial<ImageProps> = all
let layout: NonNullable<LayoutValue> = sizes ? 'responsive' : 'intrinsic' let layout: NonNullable<LayoutValue> = sizes ? 'responsive' : 'intrinsic'
let unsized = false if ('layout' in rest) {
if ('unsized' in rest) {
unsized = Boolean(rest.unsized)
// Remove property so it's not spread into image:
delete rest['unsized']
} else if ('layout' in rest) {
// Override default layout if the user specified one: // Override default layout if the user specified one:
if (rest.layout) layout = rest.layout if (rest.layout) layout = rest.layout
...@@ -304,11 +293,6 @@ export default function Image({ ...@@ -304,11 +293,6 @@ export default function Image({
`Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.` `Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.`
) )
} }
if (unsized) {
throw new Error(
`Image with src "${src}" has deprecated "unsized" property, which was removed in favor of the "layout='fill'" property`
)
}
} }
let isLazy = let isLazy =
...@@ -461,11 +445,6 @@ export default function Image({ ...@@ -461,11 +445,6 @@ export default function Image({
}) })
} }
if (unsized) {
wrapperStyle = undefined
sizerStyle = undefined
imgStyle = undefined
}
return ( return (
<div style={wrapperStyle}> <div style={wrapperStyle}>
{sizerStyle ? ( {sizerStyle ? (
......
...@@ -33,16 +33,9 @@ export type LoadableBaseOptions<P = {}> = LoadableGeneratedOptions & { ...@@ -33,16 +33,9 @@ export type LoadableBaseOptions<P = {}> = LoadableGeneratedOptions & {
ssr?: boolean ssr?: boolean
} }
export type LoadableOptions<P = {}> = LoadableBaseOptions<P> & { export type LoadableOptions<P = {}> = LoadableBaseOptions<P>
render?(loader: any, props: any): JSX.Element
}
export type DynamicOptions<P = {}> = LoadableBaseOptions<P> & { export type DynamicOptions<P = {}> = LoadableBaseOptions<P>
/**
* @deprecated the modules option has been planned for removal
*/
render?(props: P, loaded: any): JSX.Element
}
export type LoadableFn<P = {}> = ( export type LoadableFn<P = {}> = (
opts: LoadableOptions<P> opts: LoadableOptions<P>
...@@ -117,40 +110,6 @@ export default function dynamic<P = {}>( ...@@ -117,40 +110,6 @@ export default function dynamic<P = {}>(
// Support for passing options, eg: dynamic(import('../hello-world'), {loading: () => <p>Loading something</p>}) // Support for passing options, eg: dynamic(import('../hello-world'), {loading: () => <p>Loading something</p>})
loadableOptions = { ...loadableOptions, ...options } loadableOptions = { ...loadableOptions, ...options }
if (
typeof dynamicOptions === 'object' &&
!(dynamicOptions instanceof Promise)
) {
// show deprecation warning for `modules` key in development
if (process.env.NODE_ENV !== 'production') {
if (dynamicOptions.modules) {
console.warn(
'The modules option for next/dynamic has been deprecated. See here for more info https://nextjs.org/docs/messages/next-dynamic-modules'
)
}
}
// Support for `render` when using a mapping, eg: `dynamic({ modules: () => {return {HelloWorld: import('../hello-world')}, render(props, loaded) {} } })
if (dynamicOptions.render) {
loadableOptions.render = (loaded, props) =>
dynamicOptions.render!(props, loaded)
}
// Support for `modules` when using a mapping, eg: `dynamic({ modules: () => {return {HelloWorld: import('../hello-world')}, render(props, loaded) {} } })
if (dynamicOptions.modules) {
loadableFn = Loadable.Map
const loadModules: LoaderMap = {}
const modules = dynamicOptions.modules()
Object.keys(modules).forEach((key) => {
const value: any = modules[key]
if (typeof value.then === 'function') {
loadModules[key] = () => value.then((mod: any) => mod.default || mod)
return
}
loadModules[key] = value
})
loadableOptions.loader = loadModules
}
}
// coming from build/babel/plugins/react-loadable-plugin.js // coming from build/babel/plugins/react-loadable-plugin.js
if (loadableOptions.loadableGenerated) { if (loadableOptions.loadableGenerated) {
loadableOptions = { loadableOptions = {
......
...@@ -53,61 +53,10 @@ function load(loader) { ...@@ -53,61 +53,10 @@ function load(loader) {
return state return state
} }
function loadMap(obj) {
let state = {
loading: false,
loaded: {},
error: null,
}
let promises = []
try {
Object.keys(obj).forEach((key) => {
let result = load(obj[key])
if (!result.loading) {
state.loaded[key] = result.loaded
state.error = result.error
} else {
state.loading = true
}
promises.push(result.promise)
result.promise
.then((res) => {
state.loaded[key] = res
})
.catch((err) => {
state.error = err
})
})
} catch (err) {
state.error = err
}
state.promise = Promise.all(promises)
.then((res) => {
state.loading = false
return res
})
.catch((err) => {
state.loading = false
throw err
})
return state
}
function resolve(obj) { function resolve(obj) {
return obj && obj.__esModule ? obj.default : obj return obj && obj.__esModule ? obj.default : obj
} }
function render(loaded, props) {
return React.createElement(resolve(loaded), props)
}
function createLoadableComponent(loadFn, options) { function createLoadableComponent(loadFn, options) {
let opts = Object.assign( let opts = Object.assign(
{ {
...@@ -115,7 +64,6 @@ function createLoadableComponent(loadFn, options) { ...@@ -115,7 +64,6 @@ function createLoadableComponent(loadFn, options) {
loading: null, loading: null,
delay: 200, delay: 200,
timeout: null, timeout: null,
render: render,
webpack: null, webpack: null,
modules: null, modules: null,
}, },
...@@ -188,7 +136,7 @@ function createLoadableComponent(loadFn, options) { ...@@ -188,7 +136,7 @@ function createLoadableComponent(loadFn, options) {
retry: subscription.retry, retry: subscription.retry,
}) })
} else if (state.loaded) { } else if (state.loaded) {
return opts.render(state.loaded, props) return React.createElement(resolve(state.loaded), props)
} else { } else {
return null return null
} }
...@@ -291,16 +239,6 @@ function Loadable(opts) { ...@@ -291,16 +239,6 @@ function Loadable(opts) {
return createLoadableComponent(load, opts) return createLoadableComponent(load, opts)
} }
function LoadableMap(opts) {
if (typeof opts.render !== 'function') {
throw new Error('LoadableMap requires a `render(loaded, props)` function')
}
return createLoadableComponent(loadMap, opts)
}
Loadable.Map = LoadableMap
function flushInitializers(initializers, ids) { function flushInitializers(initializers, ids) {
let promises = [] let promises = []
......
import React, { ErrorInfo } from 'react' import React from 'react'
import { import {
execOnce,
loadGetInitialProps, loadGetInitialProps,
AppContextType, AppContextType,
AppInitialProps, AppInitialProps,
...@@ -36,94 +35,9 @@ export default class App<P = {}, CP = {}, S = {}> extends React.Component< ...@@ -36,94 +35,9 @@ export default class App<P = {}, CP = {}, S = {}> extends React.Component<
static origGetInitialProps = appGetInitialProps static origGetInitialProps = appGetInitialProps
static getInitialProps = appGetInitialProps static getInitialProps = appGetInitialProps
// Kept here for backwards compatibility.
// When someone ended App they could call `super.componentDidCatch`.
// @deprecated This method is no longer needed. Errors are caught at the top level
componentDidCatch(error: Error, _errorInfo: ErrorInfo): void {
throw error
}
render() { render() {
const { router, Component, pageProps, __N_SSG, __N_SSP } = this const { Component, pageProps } = this.props as AppProps<CP>
.props as AppProps<CP>
return (
<Component
{...pageProps}
{
// we don't add the legacy URL prop if it's using non-legacy
// methods like getStaticProps and getServerSideProps
...(!(__N_SSG || __N_SSP) ? { url: createUrl(router) } : {})
}
/>
)
}
}
let warnContainer: () => void
let warnUrl: () => void
if (process.env.NODE_ENV !== 'production') {
warnContainer = execOnce(() => {
console.warn(
`Warning: the \`Container\` in \`_app\` has been deprecated and should be removed. https://nextjs.org/docs/messages/app-container-deprecated`
)
})
warnUrl = execOnce(() => {
console.error(
`Warning: the 'url' property is deprecated. https://nextjs.org/docs/messages/url-deprecated`
)
})
}
// @deprecated noop for now until removal
export function Container(p: any) {
if (process.env.NODE_ENV !== 'production') warnContainer()
return p.children
}
export function createUrl(router: Router) {
// This is to make sure we don't references the router object at call time
const { pathname, asPath, query } = router
return {
get query() {
if (process.env.NODE_ENV !== 'production') warnUrl()
return query
},
get pathname() {
if (process.env.NODE_ENV !== 'production') warnUrl()
return pathname
},
get asPath() {
if (process.env.NODE_ENV !== 'production') warnUrl()
return asPath
},
back: () => {
if (process.env.NODE_ENV !== 'production') warnUrl()
router.back()
},
push: (url: string, as?: string) => {
if (process.env.NODE_ENV !== 'production') warnUrl()
return router.push(url, as)
},
pushTo: (href: string, as?: string) => {
if (process.env.NODE_ENV !== 'production') warnUrl()
const pushRoute = as ? href : ''
const pushUrl = as || href
return router.push(pushRoute, pushUrl)
},
replace: (url: string, as?: string) => {
if (process.env.NODE_ENV !== 'production') warnUrl()
return router.replace(url, as)
},
replaceTo: (href: string, as?: string) => {
if (process.env.NODE_ENV !== 'production') warnUrl()
const replaceRoute = as ? href : ''
const replaceUrl = as || href
return router.replace(replaceRoute, replaceUrl) return <Component {...pageProps} />
},
} }
} }
import React from 'react'
import dynamic from 'next/dynamic'
import Router from 'next/router'
import PropTypes from 'prop-types'
const HelloBundle = dynamic({
modules: (props) => {
const components = {
HelloContext: import('../../components/hello-context'),
Hello1: import('../../components/hello1'),
Hello2: import('../../components/hello2'),
}
return components
},
render: (props, { HelloContext, Hello1, Hello2 }) => (
<div>
<h1>{props.title}</h1>
<HelloContext />
<Hello1 />
{props.showMore ? <Hello2 /> : null}
</div>
),
})
export default class Bundle extends React.Component {
static childContextTypes = {
data: PropTypes.object,
}
static getInitialProps({ query }) {
return { showMore: Boolean(query.showMore) }
}
getChildContext() {
return {
data: { title: 'Vercel Rocks' },
}
}
toggleShowMore() {
if (this.props.showMore) {
Router.push('/dynamic/bundle')
return
}
Router.push('/dynamic/bundle?showMore=1')
}
render() {
const { showMore } = this.props
return (
<div>
<HelloBundle showMore={showMore} title="Dynamic Bundle" />
<button id="toggle-show-more" onClick={() => this.toggleShowMore()}>
Toggle Show More
</button>
</div>
)
}
}
/* eslint-env jest */ /* eslint-env jest */
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { waitFor, check } from 'next-test-utils' import { check } from 'next-test-utils'
export default (context, render) => { export default (context, render) => {
async function get$(path, query) { async function get$(path, query) {
...@@ -227,76 +227,5 @@ export default (context, render) => { ...@@ -227,76 +227,5 @@ export default (context, render) => {
} }
}) })
}) })
describe('Import mapping', () => {
it('should render dynamic imports bundle', async () => {
const $ = await get$('/dynamic/bundle')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(false)
})
it('should render dynamic imports bundle with additional components', async () => {
const $ = await get$('/dynamic/bundle?showMore=1')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(true)
})
it('should render components', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
!/Hello World 2/.test(bodyText)
) {
break
}
await waitFor(1000)
}
await browser.close()
})
it('should render support React context', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (/Vercel Rocks/.test(bodyText)) break
await waitFor(1000)
}
await browser.close()
})
it('should load new components and render for prop changes', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
await browser
.waitForElementByCss('#toggle-show-more')
.elementByCss('#toggle-show-more')
.click()
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
/Hello World 2/.test(bodyText)
) {
break
}
await waitFor(1000)
}
await browser.close()
})
})
}) })
} }
...@@ -123,22 +123,22 @@ describe('Build Output', () => { ...@@ -123,22 +123,22 @@ describe('Build Output', () => {
) )
expect(indexSize.endsWith('B')).toBe(true) expect(indexSize.endsWith('B')).toBe(true)
expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 63.5 : 195, 1) expect(parseFloat(indexFirstLoad)).toBeCloseTo(gz ? 63.3 : 194, 1)
expect(indexFirstLoad.endsWith('kB')).toBe(true) expect(indexFirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.06 : 8.15, 1) expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.06 : 8.15, 1)
expect(err404Size.endsWith('kB')).toBe(true) expect(err404Size.endsWith('kB')).toBe(true)
expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.3 : 203, 1) expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.1 : 202, 1)
expect(err404FirstLoad.endsWith('kB')).toBe(true) expect(err404FirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.2 : 194, 1) expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63 : 194, 1)
expect(sharedByAll.endsWith('kB')).toBe(true) expect(sharedByAll.endsWith('kB')).toBe(true)
const appSizeValue = _appSize.endsWith('kB') const appSizeValue = _appSize.endsWith('kB')
? parseFloat(_appSize) ? parseFloat(_appSize)
: parseFloat(_appSize) / 1000 : parseFloat(_appSize) / 1000
expect(appSizeValue).toBeCloseTo(gz ? 1.0 : 2.18, 1) expect(appSizeValue).toBeCloseTo(gz ? 0.799 : 1.63, 1)
expect(_appSize.endsWith('kB') || _appSize.endsWith(' B')).toBe(true) expect(_appSize.endsWith('kB') || _appSize.endsWith(' B')).toBe(true)
const webpackSizeValue = webpackSize.endsWith('kB') const webpackSizeValue = webpackSize.endsWith('kB')
......
import { Component } from 'react' import { Component } from 'react'
import Link from 'next/link' import Link from 'next/link'
import Router from 'next/router' import Router, { withRouter } from 'next/router'
let getInitialPropsRunCount = 1 let getInitialPropsRunCount = 1
...@@ -8,60 +8,62 @@ const linkStyle = { ...@@ -8,60 +8,62 @@ const linkStyle = {
marginRight: 10, marginRight: 10,
} }
export default class extends Component { export default withRouter(
static getInitialProps({ res }) { class extends Component {
if (res) return { getInitialPropsRunCount: 1 } static getInitialProps({ res }) {
getInitialPropsRunCount++ if (res) return { getInitialPropsRunCount: 1 }
getInitialPropsRunCount++
return { getInitialPropsRunCount } return { getInitialPropsRunCount }
} }
getCurrentCounter() { getCurrentCounter() {
const { url } = this.props const { router } = this.props
return url.query.counter ? parseInt(url.query.counter) : 0 return router.query.counter ? parseInt(router.query.counter) : 0
} }
increase() { increase() {
const counter = this.getCurrentCounter() const counter = this.getCurrentCounter()
const href = `/nav/shallow-routing?counter=${counter + 1}` const href = `/nav/shallow-routing?counter=${counter + 1}`
Router.push(href, href, { shallow: true }) Router.push(href, href, { shallow: true })
} }
increaseNonShallow() { increaseNonShallow() {
const counter = this.getCurrentCounter() const counter = this.getCurrentCounter()
const href = `/nav/shallow-routing?counter=${counter + 1}` const href = `/nav/shallow-routing?counter=${counter + 1}`
Router.push(href, href, {}) Router.push(href, href, {})
} }
gotoNavShallow() { gotoNavShallow() {
const href = `/nav` const href = `/nav`
Router.push(href, href, { shallow: true }) Router.push(href, href, { shallow: true })
} }
render() { render() {
return ( return (
<div className="shallow-routing"> <div className="shallow-routing">
<Link href="/nav"> <Link href="/nav">
<a id="home-link" style={linkStyle}> <a id="home-link" style={linkStyle}>
Home Home
</a> </a>
</Link> </Link>
<div id="counter" style={{ marginBottom: 4000 }}> <div id="counter" style={{ marginBottom: 4000 }}>
Counter: {this.getCurrentCounter()} Counter: {this.getCurrentCounter()}
</div> </div>
<div id="get-initial-props-run-count"> <div id="get-initial-props-run-count">
getInitialProps run count: {this.props.getInitialPropsRunCount} getInitialProps run count: {this.props.getInitialPropsRunCount}
</div>
<button id="increase" onClick={() => this.increase()}>
Increase
</button>
<button id="increase2" onClick={() => this.increaseNonShallow()}>
Increase Non-Shallow
</button>
<button id="invalidShallow" onClick={() => this.gotoNavShallow()}>
Invalid Shallow Nav
</button>
</div> </div>
<button id="increase" onClick={() => this.increase()}> )
Increase }
</button>
<button id="increase2" onClick={() => this.increaseNonShallow()}>
Increase Non-Shallow
</button>
<button id="invalidShallow" onClick={() => this.gotoNavShallow()}>
Invalid Shallow Nav
</button>
</div>
)
} }
} )
import React from 'react'
import Link from 'next/link'
export default class UrlPropChange extends React.Component {
constructor(props) {
super(props)
this.state = {
previousUrl: {},
url: props.url,
}
}
componentDidUpdate(prevProps) {
if (prevProps.url !== this.props.url) {
this.setState(() => {
return {
previousUrl: prevProps.url,
url: this.props.url,
}
})
}
}
render() {
const { previousUrl, url } = this.state
return (
<div>
Current:
<div id="url-result">{JSON.stringify(url)}</div>
<br />
<br />
Previous:
<div id="previous-url-result">{JSON.stringify(previousUrl)}</div>
<Link href="/nav/url-prop-change?added=yes">
<a id="add-query">Add querystring</a>
</Link>
</div>
)
}
}
import React from 'react'
export default class extends React.Component {
static getInitialProps() {
return {
url: 'test', // This gets overridden by Next in lib/_app.js
}
}
render() {
const { url } = this.props
return (
<div>
<p id="pathname">{url.pathname}</p>
<p id="query">{Object.keys(url.query).length}</p>
<p id="aspath">{url.asPath}</p>
</div>
)
}
}
const Page = ({ url }) => {
return (
<div>
<p id="pathname">{url.pathname}</p>
<p id="query">{Object.keys(url.query).length}</p>
<p id="aspath">{url.asPath}</p>
</div>
)
}
Page.getInitialProps = () => ({})
export default Page
...@@ -42,7 +42,6 @@ describe('Client Navigation', () => { ...@@ -42,7 +42,6 @@ describe('Client Navigation', () => {
'/styled-jsx-external', '/styled-jsx-external',
'/with-cdm', '/with-cdm',
'/url-prop', '/url-prop',
'/url-prop-override',
'/dynamic/ssr', '/dynamic/ssr',
'/dynamic/[slug]/route', '/dynamic/[slug]/route',
...@@ -57,7 +56,6 @@ describe('Client Navigation', () => { ...@@ -57,7 +56,6 @@ describe('Client Navigation', () => {
'/nav/redirect', '/nav/redirect',
'/nav/as-path', '/nav/as-path',
'/nav/as-path-using-router', '/nav/as-path-using-router',
'/nav/url-prop-change',
'/nested-cdm', '/nested-cdm',
] ]
...@@ -169,30 +167,6 @@ describe('Client Navigation', () => { ...@@ -169,30 +167,6 @@ describe('Client Navigation', () => {
}) })
}) })
describe('With url property', () => {
it('Should keep immutable pathname, asPath and query', async () => {
const browser = await webdriver(context.appPort, '/nav/url-prop-change')
await browser.elementByCss('#add-query').click()
const urlResult = await browser.elementByCss('#url-result').text()
const previousUrlResult = await browser
.elementByCss('#previous-url-result')
.text()
expect(JSON.parse(urlResult)).toMatchObject({
query: { added: 'yes' },
pathname: '/nav/url-prop-change',
asPath: '/nav/url-prop-change?added=yes',
})
expect(JSON.parse(previousUrlResult)).toMatchObject({
query: {},
pathname: '/nav/url-prop-change',
asPath: '/nav/url-prop-change',
})
await browser.close()
})
})
describe('with <a/> tag inside the <Link />', () => { describe('with <a/> tag inside the <Link />', () => {
it('should navigate the page', async () => { it('should navigate the page', async () => {
const browser = await webdriver(context.appPort, '/nav/about') const browser = await webdriver(context.appPort, '/nav/about')
......
...@@ -209,7 +209,7 @@ export default function (render, fetch, ctx) { ...@@ -209,7 +209,7 @@ export default function (render, fetch, ctx) {
}) })
it('should render the page without `nextExport` property', async () => { it('should render the page without `nextExport` property', async () => {
const html = await render('/url-prop') const html = await render('/async-props')
expect(html).not.toContain('"nextExport"') expect(html).not.toContain('"nextExport"')
}) })
...@@ -376,22 +376,6 @@ export default function (render, fetch, ctx) { ...@@ -376,22 +376,6 @@ export default function (render, fetch, ctx) {
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10') expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')
}) })
describe('Url prop', () => {
it('should provide pathname, query and asPath', async () => {
const $ = await get$('/url-prop')
expect($('#pathname').text()).toBe('/url-prop')
expect($('#query').text()).toBe('0')
expect($('#aspath').text()).toBe('/url-prop')
})
it('should override props.url, even when getInitialProps returns url as property', async () => {
const $ = await get$('/url-prop-override')
expect($('#pathname').text()).toBe('/url-prop-override')
expect($('#query').text()).toBe('0')
expect($('#aspath').text()).toBe('/url-prop-override')
})
})
describe('404', () => { describe('404', () => {
it('should 404 on not existent page', async () => { it('should 404 on not existent page', async () => {
const $ = await get$('/non-existent') const $ = await get$('/non-existent')
......
import React from 'react'
import Image from 'next/image'
const Page = () => {
return (
<div>
<p>Invalid Unsized</p>
<Image id="unsized-image" src="/docs/test.png" unsized />
</div>
)
}
export default Page
...@@ -5,7 +5,11 @@ const Page = () => { ...@@ -5,7 +5,11 @@ const Page = () => {
return ( return (
<div> <div>
<p>Hello World</p> <p>Hello World</p>
<Image id="exif-rotation-image" src="/docs/exif-rotation.jpg" unsized /> <Image
id="exif-rotation-image"
src="/docs/exif-rotation.jpg"
layout="fill"
/>
<p id="stubtext">This is the rotated page</p> <p id="stubtext">This is the rotated page</p>
</div> </div>
) )
......
...@@ -414,15 +414,6 @@ function runTests(mode) { ...@@ -414,15 +414,6 @@ function runTests(mode) {
'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)' 'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)'
) )
}) })
it('should show invalid unsized error', async () => {
const browser = await webdriver(appPort, '/docs/invalid-unsized')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image with src "/docs/test.png" has deprecated "unsized" property, which was removed in favor of the "layout=\'fill\'" property'
)
})
} }
it('should correctly ignore prose styles', async () => { it('should correctly ignore prose styles', async () => {
...@@ -483,7 +474,7 @@ function runTests(mode) { ...@@ -483,7 +474,7 @@ function runTests(mode) {
const computedWidth = await getComputed(browser, id, 'width') const computedWidth = await getComputed(browser, id, 'width')
const computedHeight = await getComputed(browser, id, 'height') const computedHeight = await getComputed(browser, id, 'height')
expect(getRatio(computedWidth, computedHeight)).toBeCloseTo(1.333, 1) expect(getRatio(computedWidth, computedHeight)).toBeCloseTo(0.5625, 1)
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
......
...@@ -480,15 +480,6 @@ function runTests(mode) { ...@@ -480,15 +480,6 @@ function runTests(mode) {
'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)' 'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)'
) )
}) })
it('should show invalid unsized error', async () => {
const browser = await webdriver(appPort, '/invalid-unsized')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image with src "/test.png" has deprecated "unsized" property, which was removed in favor of the "layout=\'fill\'" property'
)
})
} }
it('should correctly ignore prose styles', async () => { it('should correctly ignore prose styles', async () => {
...@@ -549,7 +540,7 @@ function runTests(mode) { ...@@ -549,7 +540,7 @@ function runTests(mode) {
const computedWidth = await getComputed(browser, id, 'width') const computedWidth = await getComputed(browser, id, 'width')
const computedHeight = await getComputed(browser, id, 'height') const computedHeight = await getComputed(browser, id, 'height')
expect(getRatio(computedWidth, computedHeight)).toBeCloseTo(1.333, 1) expect(getRatio(computedWidth, computedHeight)).toBeCloseTo(0.5625, 1)
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
......
import React from 'react'
import dynamic from 'next/dynamic'
import Router from 'next/router'
import PropTypes from 'prop-types'
const HelloBundle = dynamic({
modules: () => {
const components = {
HelloContext: import('../../components/hello-context'),
Hello1: import('../../components/hello1'),
Hello2: import('../../components/hello2'),
}
return components
},
render: (props, { HelloContext, Hello1, Hello2 }) => (
<div>
<h1>{props.title}</h1>
<HelloContext />
<Hello1 />
{props.showMore ? <Hello2 /> : null}
</div>
),
})
export default class Bundle extends React.Component {
static childContextTypes = {
data: PropTypes.object,
}
static getInitialProps({ query }) {
return { showMore: Boolean(query.showMore) }
}
getChildContext() {
return {
data: { title: 'Vercel Rocks' },
}
}
toggleShowMore() {
if (this.props.showMore) {
Router.push('/dynamic/bundle')
return
}
Router.push('/dynamic/bundle?showMore=1')
}
render() {
const { showMore } = this.props
return (
<div>
<HelloBundle showMore={showMore} title="Dynamic Bundle" />
<button id="toggle-show-more" onClick={() => this.toggleShowMore()}>
Toggle Show More
</button>
</div>
)
}
}
/* eslint-env jest */ /* eslint-env jest */
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { waitFor, check } from 'next-test-utils' import { check } from 'next-test-utils'
// These tests are similar to ../../basic/test/dynamic.js // These tests are similar to ../../basic/test/dynamic.js
export default (context, render) => { export default (context, render) => {
...@@ -162,76 +162,5 @@ export default (context, render) => { ...@@ -162,76 +162,5 @@ export default (context, render) => {
} }
}) })
}) })
describe('Import mapping', () => {
it('should render dynamic imports bundle', async () => {
const $ = await get$('/dynamic/bundle')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(false)
})
it('should render dynamic imports bundle with additional components', async () => {
const $ = await get$('/dynamic/bundle?showMore=1')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(true)
})
it('should render components', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
!/Hello World 2/.test(bodyText)
) {
break
}
await waitFor(1000)
}
await browser.close()
})
it('should render support React context', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (/Vercel Rocks/.test(bodyText)) break
await waitFor(1000)
}
await browser.close()
})
it('should load new components and render for prop changes', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
await browser
.waitForElementByCss('#toggle-show-more')
.elementByCss('#toggle-show-more')
.click()
while (true) {
const bodyText = await browser.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
/Hello World 2/.test(bodyText)
) {
break
}
await waitFor(1000)
}
await browser.close()
})
})
}) })
} }
...@@ -276,11 +276,13 @@ describe('Production Usage', () => { ...@@ -276,11 +276,13 @@ describe('Production Usage', () => {
const manifestKey = Object.keys(reactLoadableManifest).find((item) => { const manifestKey = Object.keys(reactLoadableManifest).find((item) => {
return item return item
.replace(/\\/g, '/') .replace(/\\/g, '/')
.endsWith('bundle.js -> ../../components/hello1') .endsWith('dynamic/css.js -> ../../components/dynamic-css/with-css')
}) })
// test dynamic chunk // test dynamic chunk
resources.add(url + reactLoadableManifest[manifestKey].files[0]) reactLoadableManifest[manifestKey].files.forEach((f) => {
resources.add(url + f)
})
// test main.js runtime etc // test main.js runtime etc
for (const item of buildManifest.pages['/']) { for (const item of buildManifest.pages['/']) {
......
...@@ -1061,6 +1061,13 @@ ...@@ -1061,6 +1061,13 @@
dependencies: dependencies:
regenerator-runtime "^0.13.4" regenerator-runtime "^0.13.4"
"@babel/runtime@^7.11.2":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.0.tgz#46794bc20b612c5f75e62dd071e24dfd95f1cbe6"
integrity sha512-JELkvo/DlpNdJ7dlyw/eY7E0suy5i5GQH+Vlxaq1nsNJ+H7f4Vtv3jMeCEgRhZZQFXTjldYfQgv2qmM6M1v5wA==
dependencies:
regenerator-runtime "^0.13.4"
"@babel/template@^7.10.4", "@babel/template@^7.12.7", "@babel/template@^7.3.3": "@babel/template@^7.10.4", "@babel/template@^7.12.7", "@babel/template@^7.3.3":
version "7.12.7" version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.7.tgz#c817233696018e39fbb6c491d2fb684e05ed43bc" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.7.tgz#c817233696018e39fbb6c491d2fb684e05ed43bc"
...@@ -4152,6 +4159,11 @@ assign-symbols@^1.0.0: ...@@ -4152,6 +4159,11 @@ assign-symbols@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
ast-types-flow@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ast-types-flow/-/ast-types-flow-0.0.7.tgz#f70b735c6bca1a5c9c22d982c3e39e7feba3bdad"
integrity sha1-9wtzXGvKGlycItmCw+Oef+ujva0=
ast-types@0.11.7: ast-types@0.11.7:
version "0.11.7" version "0.11.7"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.7.tgz#f318bf44e339db6a320be0009ded64ec1471f46c" resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.7.tgz#f318bf44e339db6a320be0009ded64ec1471f46c"
...@@ -4262,6 +4274,16 @@ aws4@^1.8.0: ...@@ -4262,6 +4274,16 @@ aws4@^1.8.0:
version "1.9.0" version "1.9.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.0.tgz#24390e6ad61386b0a747265754d2a17219de862c" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.0.tgz#24390e6ad61386b0a747265754d2a17219de862c"
axe-core@^4.0.2:
version "4.2.1"
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.2.1.tgz#2e50bcf10ee5b819014f6e342e41e45096239e34"
integrity sha512-evY7DN8qSIbsW2H/TWQ1bX3sXN1d4MNb5Vb4n7BzPuCwRHdkZ1H2eNLuSh73EoQqkGKUtju2G2HCcjCfhvZIAA==
axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
integrity sha512-Td525n+iPOOyUQIeBfcASuG6uJsDOITl7Mds5gFyerkWiX7qhUTdYUBlSgNMyVqtSJqwpt1kXGLdUt6SykLMRA==
babel-code-frame@^6.26.0: babel-code-frame@^6.26.0:
version "6.26.0" version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
...@@ -6182,6 +6204,11 @@ d@1, d@^1.0.1: ...@@ -6182,6 +6204,11 @@ d@1, d@^1.0.1:
es5-ext "^0.10.50" es5-ext "^0.10.50"
type "^1.0.1" type "^1.0.1"
damerau-levenshtein@^1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.7.tgz#64368003512a1a6992593741a09a9d31a836f55d"
integrity sha512-VvdQIPGdWP0SqFXghj79Wf/5LArmreyMsGLa6FG6iC4t3j7j5s71TrwWmT/4akbDQIqjfACkLZmjXhA7g2oUZw==
dargs@^7.0.0: dargs@^7.0.0:
version "7.0.0" version "7.0.0"
resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc" resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc"
...@@ -6663,6 +6690,11 @@ emoji-regex@^8.0.0: ...@@ -6663,6 +6690,11 @@ emoji-regex@^8.0.0:
version "8.0.0" version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
emoji-regex@^9.0.0:
version "9.2.2"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72"
integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==
emojis-list@^2.0.0: emojis-list@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
...@@ -6944,6 +6976,23 @@ eslint-plugin-jest@24.3.5: ...@@ -6944,6 +6976,23 @@ eslint-plugin-jest@24.3.5:
dependencies: dependencies:
"@typescript-eslint/experimental-utils" "^4.0.1" "@typescript-eslint/experimental-utils" "^4.0.1"
eslint-plugin-jsx-a11y@^6.4.1:
version "6.4.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.4.1.tgz#a2d84caa49756942f42f1ffab9002436391718fd"
integrity sha512-0rGPJBbwHoGNPU73/QCLP/vveMlM1b1Z9PponxO87jfr6tuH5ligXbDT6nHSSzBC8ovX2Z+BQu7Bk5D/Xgq9zg==
dependencies:
"@babel/runtime" "^7.11.2"
aria-query "^4.2.2"
array-includes "^3.1.1"
ast-types-flow "^0.0.7"
axe-core "^4.0.2"
axobject-query "^2.2.0"
damerau-levenshtein "^1.0.6"
emoji-regex "^9.0.0"
has "^1.0.3"
jsx-ast-utils "^3.1.0"
language-tags "^1.0.5"
eslint-plugin-react-hooks@4.2.0, eslint-plugin-react-hooks@^4.2.0: eslint-plugin-react-hooks@4.2.0, eslint-plugin-react-hooks@^4.2.0:
version "4.2.0" version "4.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.2.0.tgz#8c229c268d468956334c943bb45fc860280f5556" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.2.0.tgz#8c229c268d468956334c943bb45fc860280f5556"
...@@ -10091,7 +10140,7 @@ jsprim@^1.2.2: ...@@ -10091,7 +10140,7 @@ jsprim@^1.2.2:
json-schema "0.2.3" json-schema "0.2.3"
verror "1.10.0" verror "1.10.0"
"jsx-ast-utils@^2.4.1 || ^3.0.0": "jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.1.0:
version "3.2.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.0.tgz#41108d2cec408c3453c1bbe8a4aae9e1e2bd8f82"
integrity sha512-EIsmt3O3ljsU6sot/J4E1zDRxfBNrhjyf/OKjlydwgEimQuznlM4Wv7U+ueONJMyEn1WRE0K8dhi3dVAXYT24Q== integrity sha512-EIsmt3O3ljsU6sot/J4E1zDRxfBNrhjyf/OKjlydwgEimQuznlM4Wv7U+ueONJMyEn1WRE0K8dhi3dVAXYT24Q==
...@@ -10182,6 +10231,18 @@ ky@0.19.1: ...@@ -10182,6 +10231,18 @@ ky@0.19.1:
version "0.19.1" version "0.19.1"
resolved "https://registry.yarnpkg.com/ky/-/ky-0.19.1.tgz#c533884028c83f78167d12905dfecaf6dd760bec" resolved "https://registry.yarnpkg.com/ky/-/ky-0.19.1.tgz#c533884028c83f78167d12905dfecaf6dd760bec"
language-subtag-registry@~0.3.2:
version "0.3.21"
resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.21.tgz#04ac218bea46f04cb039084602c6da9e788dd45a"
integrity sha512-L0IqwlIXjilBVVYKFT37X9Ih11Um5NEl9cbJIuU/SwP/zEEAbBPOnEeeuxVMf45ydWQRDQN3Nqc96OgbH1K+Pg==
language-tags@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/language-tags/-/language-tags-1.0.5.tgz#d321dbc4da30ba8bf3024e040fa5c14661f9193a"
integrity sha1-0yHbxNowuovzAk4ED6XBRmH5GTo=
dependencies:
language-subtag-registry "~0.3.2"
last-call-webpack-plugin@^3.0.0: last-call-webpack-plugin@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555" resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555"
......
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