= LoadableGeneratedOptions & { ssr?: boolean } -export type LoadableOptions
= LoadableBaseOptions
& { - render?(loader: any, props: any): JSX.Element -} +export type LoadableOptions
= LoadableBaseOptions
-export type DynamicOptions
= LoadableBaseOptions
& { - /** - * @deprecated the modules option has been planned for removal - */ - render?(props: P, loaded: any): JSX.Element -} +export type DynamicOptions
= LoadableBaseOptions
export type LoadableFn
= ( opts: LoadableOptions
@@ -117,40 +110,6 @@ export default function dynamic
( // Support for passing options, eg: dynamic(import('../hello-world'), {loading: () =>
Loading something
}) 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 if (loadableOptions.loadableGenerated) { loadableOptions = { diff --git a/packages/next/next-server/lib/loadable.js b/packages/next/next-server/lib/loadable.js index a81d792610ed3..3b2381b319dfb 100644 --- a/packages/next/next-server/lib/loadable.js +++ b/packages/next/next-server/lib/loadable.js @@ -53,61 +53,10 @@ function load(loader) { 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) { return obj && obj.__esModule ? obj.default : obj } -function render(loaded, props) { - return React.createElement(resolve(loaded), props) -} - function createLoadableComponent(loadFn, options) { let opts = Object.assign( { @@ -115,7 +64,6 @@ function createLoadableComponent(loadFn, options) { loading: null, delay: 200, timeout: null, - render: render, webpack: null, modules: null, }, @@ -188,7 +136,7 @@ function createLoadableComponent(loadFn, options) { retry: subscription.retry, }) } else if (state.loaded) { - return opts.render(state.loaded, props) + return React.createElement(resolve(state.loaded), props) } else { return null } @@ -291,16 +239,6 @@ function Loadable(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) { let promises = [] diff --git a/packages/next/next-server/lib/post-process.ts b/packages/next/next-server/lib/post-process.ts index 2a448f64bab56..04c9ad8225720 100644 --- a/packages/next/next-server/lib/post-process.ts +++ b/packages/next/next-server/lib/post-process.ts @@ -82,7 +82,7 @@ class FontOptimizerMiddleware implements PostProcessMiddleware { (tag: HTMLElement) => tag.getAttribute('rel') === 'stylesheet' && tag.hasAttribute('data-href') && - OPTIMIZED_FONT_PROVIDERS.some((url) => { + OPTIMIZED_FONT_PROVIDERS.some(({ url }) => { const dataHref = tag.getAttribute('data-href') return dataHref ? dataHref.startsWith(url) : false }) @@ -104,6 +104,8 @@ class FontOptimizerMiddleware implements PostProcessMiddleware { options: renderOptions ) => { let result = markup + let preconnectUrls = new Set extends React.Component<
static origGetInitialProps = 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() {
- const { router, Component, pageProps, __N_SSG, __N_SSP } = this
- .props as AppProps {url.pathname} {Object.keys(url.query).length} {url.asPath} {url.pathname} {Object.keys(url.query).length} {url.asPath}{props.title}
-
-
- Previous:
- Nav
@@ -42,3 +42,4 @@ export default () => (
>
)
+export default Page
diff --git a/test/integration/custom-routes/test/index.test.js b/test/integration/custom-routes/test/index.test.js
index 461774b7a799a..9453a19eb5fd5 100644
--- a/test/integration/custom-routes/test/index.test.js
+++ b/test/integration/custom-routes/test/index.test.js
@@ -20,6 +20,7 @@ import {
normalizeRegEx,
initNextServerScript,
nextExport,
+ hasRedbox,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
@@ -38,6 +39,42 @@ let appPort
let app
const runTests = (isDev = false) => {
+ it('should resolveHref correctly navigating through history', async () => {
+ const browser = await webdriver(appPort, '/')
+ await browser.eval('window.beforeNav = 1')
+
+ expect(await browser.eval('document.documentElement.innerHTML')).toContain(
+ 'multi-rewrites'
+ )
+
+ await browser.eval('next.router.push("/rewriting-to-auto-export")')
+ await browser.waitForElementByCss('#auto-export')
+
+ expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
+ slug: 'hello',
+ rewrite: '1',
+ })
+ expect(await browser.eval('window.beforeNav')).toBe(1)
+
+ await browser.eval('next.router.push("/nav")')
+ await browser.waitForElementByCss('#nav')
+
+ expect(await browser.elementByCss('#nav').text()).toBe('Nav')
+
+ await browser.back()
+ await browser.waitForElementByCss('#auto-export')
+
+ expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
+ slug: 'hello',
+ rewrite: '1',
+ })
+ expect(await browser.eval('window.beforeNav')).toBe(1)
+
+ if (isDev) {
+ expect(await hasRedbox(browser, false)).toBe(false)
+ }
+ })
+
it('should continue in beforeFiles rewrites', async () => {
const res = await fetchViaHTTP(appPort, '/old-blog/about')
expect(res.status).toBe(200)
diff --git a/test/integration/font-optimization/fixtures/with-google/pages/_document.js b/test/integration/font-optimization/fixtures/with-google/pages/_document.js
index f3f300181f324..6b1db914b491f 100644
--- a/test/integration/font-optimization/fixtures/with-google/pages/_document.js
+++ b/test/integration/font-optimization/fixtures/with-google/pages/_document.js
@@ -1,7 +1,6 @@
import * as React from 'react'
/// @ts-ignore
import Document, { Main, NextScript, Head } from 'next/document'
-
export default class MyDocument extends Document {
constructor(props) {
super(props)
diff --git a/test/integration/font-optimization/fixtures/with-typekit/manifest-snapshot.json b/test/integration/font-optimization/fixtures/with-typekit/manifest-snapshot.json
index 42681af1533b5..cb517f819778c 100644
--- a/test/integration/font-optimization/fixtures/with-typekit/manifest-snapshot.json
+++ b/test/integration/font-optimization/fixtures/with-typekit/manifest-snapshot.json
@@ -1,14 +1,14 @@
[
{
"url": "https://use.typekit.net/plm1izr.css",
- "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=plm1izr&ht=tk&f=32266&a=23152309&app=typekit&e=css\");@font-face{font-family:\"birra-2\";src:url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:700}.tk-birra-2{font-family:\"birra-2\",serif}@import url(\"https://p.typekit.net/p.css?s=1&k=plm1izr&ht=tk&f=32266&a=23152309&app=typekit&e=css\");@font-face{font-family:\"birra-2\";src:url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:700}.tk-birra-2{font-family:\"birra-2\",serif}"
+ "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=plm1izr&ht=tk&f=32266&a=23152309&app=typekit&e=css\");@font-face{font-family:\"birra-2\";src:url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/23e0ad/00000000000000003b9b410c/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n7&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:700}.tk-birra-2{font-family:\"birra-2\",serif}"
},
{
"url": "https://use.typekit.net/ucs7mcf.css",
- "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=ucs7mcf&ht=tk&f=43886&a=23152309&app=typekit&e=css\");@font-face{font-family:\"flegrei\";src:url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-flegrei{font-family:\"flegrei\",sans-serif}@import url(\"https://p.typekit.net/p.css?s=1&k=ucs7mcf&ht=tk&f=43886&a=23152309&app=typekit&e=css\");@font-face{font-family:\"flegrei\";src:url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-flegrei{font-family:\"flegrei\",sans-serif}"
+ "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=ucs7mcf&ht=tk&f=43886&a=23152309&app=typekit&e=css\");@font-face{font-family:\"flegrei\";src:url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/74a5d1/00000000000000003b9b3d6e/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-flegrei{font-family:\"flegrei\",sans-serif}"
},
{
"url": "https://use.typekit.net/erd0sed.css",
- "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=erd0sed&ht=tk&f=43885&a=23152309&app=typekit&e=css\");@font-face{font-family:\"pantelleria\";src:url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-pantelleria{font-family:\"pantelleria\",sans-serif}@import url(\"https://p.typekit.net/p.css?s=1&k=erd0sed&ht=tk&f=43885&a=23152309&app=typekit&e=css\");@font-face{font-family:\"pantelleria\";src:url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-pantelleria{font-family:\"pantelleria\",sans-serif}"
+ "content": "@import url(\"https://p.typekit.net/p.css?s=1&k=erd0sed&ht=tk&f=43885&a=23152309&app=typekit&e=css\");@font-face{font-family:\"pantelleria\";src:url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff2\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"woff\"),url(\"https://use.typekit.net/af/1f141c/00000000000000003b9b3d6f/27/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3\") format(\"opentype\");font-display:auto;font-style:normal;font-weight:400}.tk-pantelleria{font-family:\"pantelleria\",sans-serif}"
}
]
diff --git a/test/integration/font-optimization/test/index.test.js b/test/integration/font-optimization/test/index.test.js
index da01c47350f83..6ac704e066be8 100644
--- a/test/integration/font-optimization/test/index.test.js
+++ b/test/integration/font-optimization/test/index.test.js
@@ -54,6 +54,7 @@ describe('Font Optimization', () => {
/