Unverified Commit 5dbe0d02 authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Allow absolute urls in router and Link (#15792)

Fixes https://github.com/vercel/next.js/issues/15639
Fixes https://github.com/vercel/next.js/issues/15820

To Do:
- [x] Doesn't work with `basePath` yet
parent b6060fa4
declare const __NEXT_DATA__: any
import React, { Children } from 'react' import React, { Children } from 'react'
import { UrlObject } from 'url' import { UrlObject } from 'url'
import { PrefetchOptions, NextRouter } from '../next-server/lib/router/router' import {
import { execOnce, getLocationOrigin } from '../next-server/lib/utils' PrefetchOptions,
NextRouter,
isLocalURL,
} from '../next-server/lib/router/router'
import { execOnce } from '../next-server/lib/utils'
import { useRouter } from './router' import { useRouter } from './router'
import { addBasePath, resolveHref } from '../next-server/lib/router/router' import { addBasePath, resolveHref } from '../next-server/lib/router/router'
/**
* Detects whether a given url is from the same origin as the current page (browser only).
*/
function isLocal(url: string): boolean {
const locationOrigin = getLocationOrigin()
const resolved = new URL(url, locationOrigin)
return resolved.origin === locationOrigin
}
type Url = string | UrlObject type Url = string | UrlObject
export type LinkProps = { export type LinkProps = {
...@@ -89,6 +82,7 @@ function prefetch( ...@@ -89,6 +82,7 @@ function prefetch(
options?: PrefetchOptions options?: PrefetchOptions
): void { ): void {
if (typeof window === 'undefined') return if (typeof window === 'undefined') return
if (!isLocalURL(href)) return
// Prefetch the JSON page if asked (only in the client) // Prefetch the JSON page if asked (only in the client)
// We need to handle a prefetch error here since we may be // We need to handle a prefetch error here since we may be
// loading with priority which can reject but we don't // loading with priority which can reject but we don't
...@@ -103,6 +97,17 @@ function prefetch( ...@@ -103,6 +97,17 @@ function prefetch(
prefetched[href + '%' + as] = true prefetched[href + '%' + as] = true
} }
function isNewTabRequest(event: React.MouseEvent) {
const { target } = event.currentTarget as HTMLAnchorElement
return (
(target && target !== '_self') ||
event.metaKey ||
event.ctrlKey ||
event.shiftKey ||
(event.nativeEvent && event.nativeEvent.which === 2)
)
}
function linkClicked( function linkClicked(
e: React.MouseEvent, e: React.MouseEvent,
router: NextRouter, router: NextRouter,
...@@ -112,21 +117,10 @@ function linkClicked( ...@@ -112,21 +117,10 @@ function linkClicked(
shallow?: boolean, shallow?: boolean,
scroll?: boolean scroll?: boolean
): void { ): void {
const { nodeName, target } = e.currentTarget as HTMLAnchorElement const { nodeName } = e.currentTarget
if (
nodeName === 'A' &&
((target && target !== '_self') ||
e.metaKey ||
e.ctrlKey ||
e.shiftKey ||
(e.nativeEvent && e.nativeEvent.which === 2))
) {
// ignore click for new tab / new window behavior
return
}
if (!isLocal(href)) { if (nodeName === 'A' && (isNewTabRequest(e) || !isLocalURL(href))) {
// ignore click if it's outside our scope (e.g. https://google.com) // ignore click for new tab / new window behavior
return return
} }
...@@ -177,7 +171,13 @@ function Link(props: React.PropsWithChildren<LinkProps>) { ...@@ -177,7 +171,13 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
}, [pathname, props.href, props.as]) }, [pathname, props.href, props.as])
React.useEffect(() => { React.useEffect(() => {
if (p && IntersectionObserver && childElm && childElm.tagName) { if (
p &&
IntersectionObserver &&
childElm &&
childElm.tagName &&
isLocalURL(href)
) {
// Join on an invalid URI character // Join on an invalid URI character
const isPrefetched = prefetched[href + '%' + as] const isPrefetched = prefetched[href + '%' + as]
if (!isPrefetched) { if (!isPrefetched) {
...@@ -224,6 +224,7 @@ function Link(props: React.PropsWithChildren<LinkProps>) { ...@@ -224,6 +224,7 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
if (p) { if (p) {
childProps.onMouseEnter = (e: React.MouseEvent) => { childProps.onMouseEnter = (e: React.MouseEvent) => {
if (!isLocalURL(href)) return
if (child.props && typeof child.props.onMouseEnter === 'function') { if (child.props && typeof child.props.onMouseEnter === 'function') {
child.props.onMouseEnter(e) child.props.onMouseEnter(e)
} }
......
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
loadGetInitialProps, loadGetInitialProps,
NextPageContext, NextPageContext,
ST, ST,
getLocationOrigin,
} from '../utils' } from '../utils'
import { isDynamicRoute } from './utils/is-dynamic' import { isDynamicRoute } from './utils/is-dynamic'
import { getRouteMatcher } from './utils/route-matcher' import { getRouteMatcher } from './utils/route-matcher'
...@@ -47,7 +48,8 @@ export function hasBasePath(path: string): boolean { ...@@ -47,7 +48,8 @@ export function hasBasePath(path: string): boolean {
} }
export function addBasePath(path: string): string { export function addBasePath(path: string): string {
return basePath // we only add the basepath on relative urls
return basePath && path.startsWith('/')
? path === '/' ? path === '/'
? normalizePathTrailingSlash(basePath) ? normalizePathTrailingSlash(basePath)
: basePath + path : basePath + path
...@@ -58,6 +60,21 @@ export function delBasePath(path: string): string { ...@@ -58,6 +60,21 @@ export function delBasePath(path: string): string {
return path.slice(basePath.length) || '/' return path.slice(basePath.length) || '/'
} }
/**
* Detects whether a given url is routable by the Next.js router (browser only).
*/
export function isLocalURL(url: string): boolean {
if (url.startsWith('/')) return true
try {
// absolute urls can be local if they are on the same origin
const locationOrigin = getLocationOrigin()
const resolved = new URL(url, locationOrigin)
return resolved.origin === locationOrigin && hasBasePath(resolved.pathname)
} catch (_) {
return false
}
}
type Url = UrlObject | string type Url = UrlObject | string
/** /**
...@@ -69,12 +86,16 @@ export function resolveHref(currentPath: string, href: Url): string { ...@@ -69,12 +86,16 @@ export function resolveHref(currentPath: string, href: Url): string {
const base = new URL(currentPath, 'http://n') const base = new URL(currentPath, 'http://n')
const urlAsString = const urlAsString =
typeof href === 'string' ? href : formatWithValidation(href) typeof href === 'string' ? href : formatWithValidation(href)
const finalUrl = new URL(urlAsString, base) try {
finalUrl.pathname = normalizePathTrailingSlash(finalUrl.pathname) const finalUrl = new URL(urlAsString, base)
// if the origin didn't change, it means we received a relative href finalUrl.pathname = normalizePathTrailingSlash(finalUrl.pathname)
return finalUrl.origin === base.origin // if the origin didn't change, it means we received a relative href
? finalUrl.href.slice(finalUrl.origin.length) return finalUrl.origin === base.origin
: finalUrl.href ? finalUrl.href.slice(finalUrl.origin.length)
: finalUrl.href
} catch (_) {
return urlAsString
}
} }
function prepareUrlAs(router: NextRouter, url: Url, as: Url) { function prepareUrlAs(router: NextRouter, url: Url, as: Url) {
...@@ -93,9 +114,11 @@ function tryParseRelativeUrl( ...@@ -93,9 +114,11 @@ function tryParseRelativeUrl(
return parseRelativeUrl(url) return parseRelativeUrl(url)
} catch (err) { } catch (err) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
throw new Error( setTimeout(() => {
`Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed` throw new Error(
) `Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`
)
}, 0)
} }
return null return null
} }
...@@ -434,6 +457,11 @@ export default class Router implements BaseRouter { ...@@ -434,6 +457,11 @@ export default class Router implements BaseRouter {
as: string, as: string,
options: TransitionOptions options: TransitionOptions
): Promise<boolean> { ): Promise<boolean> {
if (!isLocalURL(url)) {
window.location.href = url
return false
}
if (!(options as any)._h) { if (!(options as any)._h) {
this.isSsr = false this.isSsr = false
} }
......
const DUMMY_BASE = new URL('http://n') import { getLocationOrigin } from '../../utils'
const DUMMY_BASE = new URL(
typeof window === 'undefined' ? 'http://n' : getLocationOrigin()
)
/** /**
* Parses path-relative urls (e.g. `/hello/world?foo=bar`). If url isn't path-relative * Parses path-relative urls (e.g. `/hello/world?foo=bar`). If url isn't path-relative
* (e.g. `./hello`) then at least base must be. * (e.g. `./hello`) then at least base must be.
* Absolute urls are rejected. * Absolute urls are rejected with one exception, in the browser, absolute urls that are on
* the current origin will be parsed as relative
*/ */
export function parseRelativeUrl(url: string, base?: string) { export function parseRelativeUrl(url: string, base?: string) {
const resolvedBase = base ? new URL(base, DUMMY_BASE) : DUMMY_BASE const resolvedBase = base ? new URL(base, DUMMY_BASE) : DUMMY_BASE
const { pathname, searchParams, search, hash, href, origin } = new URL( const {
url, pathname,
resolvedBase searchParams,
) search,
if (origin !== DUMMY_BASE.origin) { hash,
href,
origin,
protocol,
} = new URL(url, resolvedBase)
if (
origin !== DUMMY_BASE.origin ||
(protocol !== 'http:' && protocol !== 'https:')
) {
throw new Error('invariant: invalid relative URL') throw new Error('invariant: invalid relative URL')
} }
return { return {
......
import React from 'react'
import Link from 'next/link'
export async function getServerSideProps({ query: { port } }) {
if (!port) {
throw new Error('port required')
}
return { props: { port } }
}
export default function Page({ port }) {
return (
<>
<Link href={`http://localhost:${port}/docs/something-else`}>
<a id="absolute-link">http://localhost:{port}/docs/something-else</a>
</Link>
</>
)
}
import React from 'react'
import Link from 'next/link'
export async function getServerSideProps({ query: { port } }) {
if (!port) {
throw new Error('port required')
}
return { props: { port } }
}
export default function Page({ port }) {
return (
<>
<Link href={`http://localhost:${port}/rewrite-no-basepath`}>
<a id="absolute-link">http://localhost:{port}/rewrite-no-basepath</a>
</Link>
</>
)
}
import React from 'react'
import Link from 'next/link'
export default function Page() {
return (
<>
<Link href="https://vercel.com/">
<a id="absolute-link">https://vercel.com/</a>
</Link>
<br />
<Link href="mailto:idk@idk.com">
<a id="mailto-link">mailto:idk@idk.com</a>
</Link>
</>
)
}
...@@ -390,6 +390,45 @@ const runTests = (context, dev = false) => { ...@@ -390,6 +390,45 @@ const runTests = (context, dev = false) => {
expect(pathname).toBe('/docs') expect(pathname).toBe('/docs')
}) })
it('should navigate an absolute url', async () => {
const browser = await webdriver(context.appPort, `/docs/absolute-url`)
await browser.waitForElementByCss('#absolute-link').click()
await check(
() => browser.eval(() => window.location.origin),
'https://vercel.com'
)
})
it('should navigate an absolute local url with basePath', async () => {
const browser = await webdriver(
context.appPort,
`/docs/absolute-url-basepath?port=${context.appPort}`
)
await browser.eval(() => (window._didNotNavigate = true))
await browser.waitForElementByCss('#absolute-link').click()
const text = await browser
.waitForElementByCss('#something-else-page')
.text()
expect(text).toBe('something else')
expect(await browser.eval(() => window._didNotNavigate)).toBe(true)
})
it('should navigate an absolute local url without basePath', async () => {
const browser = await webdriver(
context.appPort,
`/docs/absolute-url-no-basepath?port=${context.appPort}`
)
await browser.waitForElementByCss('#absolute-link').click()
await check(
() => browser.eval(() => location.pathname),
'/rewrite-no-basepath'
)
const text = await browser.elementByCss('body').text()
expect(text).toBe('hello from external')
})
it('should 404 when manually adding basePath with <Link>', async () => { it('should 404 when manually adding basePath with <Link>', async () => {
const browser = await webdriver( const browser = await webdriver(
context.appPort, context.appPort,
......
...@@ -104,7 +104,7 @@ describe('Build Output', () => { ...@@ -104,7 +104,7 @@ describe('Build Output', () => {
expect(parseFloat(err404FirstLoad) - 63).toBeLessThanOrEqual(0) expect(parseFloat(err404FirstLoad) - 63).toBeLessThanOrEqual(0)
expect(err404FirstLoad.endsWith('kB')).toBe(true) expect(err404FirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(sharedByAll) - 59.3).toBeLessThanOrEqual(0) expect(parseFloat(sharedByAll) - 59.4).toBeLessThanOrEqual(0)
expect(sharedByAll.endsWith('kB')).toBe(true) expect(sharedByAll.endsWith('kB')).toBe(true)
if (_appSize.endsWith('kB')) { if (_appSize.endsWith('kB')) {
......
import React from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
export async function getServerSideProps({ query: { port } }) {
if (!port) {
throw new Error('port required')
}
return { props: { port } }
}
export default function Page({ port }) {
const router = useRouter()
return (
<>
<Link href="https://vercel.com/">
<a id="absolute-link">https://vercel.com/</a>
</Link>
<br />
<button
id="router-push"
onClick={() => router.push('https://vercel.com/')}
>
push https://vercel.com/
</button>
<br />
<button
id="router-replace"
onClick={() => router.replace('https://vercel.com/')}
>
replace https://vercel.com/
</button>
<br />
<Link href={`http://localhost:${port}/nav/about`}>
<a id="absolute-local-link">http://localhost:{port}/nav/about</a>
</Link>
<br />
<Link
href={`http://localhost:${port}/dynamic/[slug]/route`}
as={`http://localhost:${port}/dynamic/hello/route`}
>
<a id="absolute-local-dynamic-link">
http://localhost:{port}/dynamic/hello/route
</a>
</Link>
<br />
<button
id="router-local-push"
onClick={() => router.push(`http://localhost:${port}/nav/about`)}
>
push http://localhost:{port}/nav/about
</button>
<br />
<button
id="router-local-replace"
onClick={() => router.replace(`http://localhost:${port}/nav/about`)}
>
replace http://localhost:{port}/nav/about
</button>
<br />
<Link href="mailto:idk@idk.com">
<a id="mailto-link">mailto:idk@idk.com</a>
</Link>
</>
)
}
...@@ -8,6 +8,6 @@ export default class DynamicRoute extends React.Component { ...@@ -8,6 +8,6 @@ export default class DynamicRoute extends React.Component {
} }
render() { render() {
return <p>{this.props.query.slug}</p> return <p id="dynamic-page">{this.props.query.slug}</p>
} }
} }
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
launchApp, launchApp,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
check,
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
...@@ -124,6 +125,47 @@ describe('Client Navigation', () => { ...@@ -124,6 +125,47 @@ describe('Client Navigation', () => {
expect(counterText).toBe('Counter: 1') expect(counterText).toBe('Counter: 1')
await browser.close() await browser.close()
}) })
it('should navigate an absolute url', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.waitForElementByCss('#absolute-link').click()
await check(
() => browser.eval(() => window.location.origin),
'https://vercel.com'
)
})
it('should navigate an absolute local url', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.eval(() => (window._didNotNavigate = true))
await browser.waitForElementByCss('#absolute-local-link').click()
const text = await browser
.waitForElementByCss('.nav-about')
.elementByCss('p')
.text()
expect(text).toBe('This is the about page.')
expect(await browser.eval(() => window._didNotNavigate)).toBe(true)
})
it('should navigate an absolute local url with as', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.eval(() => (window._didNotNavigate = true))
await browser.waitForElementByCss('#absolute-local-dynamic-link').click()
expect(await browser.waitForElementByCss('#dynamic-page').text()).toBe(
'hello'
)
expect(await browser.eval(() => window._didNotNavigate)).toBe(true)
})
}) })
describe('With url property', () => { describe('With url property', () => {
...@@ -872,6 +914,60 @@ describe('Client Navigation', () => { ...@@ -872,6 +914,60 @@ describe('Client Navigation', () => {
expect(asPath).toBe('/nav/as-path-using-router') expect(asPath).toBe('/nav/as-path-using-router')
await browser.close() await browser.close()
}) })
it('should navigate an absolute url on push', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.waitForElementByCss('#router-push').click()
await check(
() => browser.eval(() => window.location.origin),
'https://vercel.com'
)
})
it('should navigate an absolute url on replace', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.waitForElementByCss('#router-replace').click()
await check(
() => browser.eval(() => window.location.origin),
'https://vercel.com'
)
})
it('should navigate an absolute local url on push', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.eval(() => (window._didNotNavigate = true))
await browser.waitForElementByCss('#router-local-push').click()
const text = await browser
.waitForElementByCss('.nav-about')
.elementByCss('p')
.text()
expect(text).toBe('This is the about page.')
expect(await browser.eval(() => window._didNotNavigate)).toBe(true)
})
it('should navigate an absolute local url on replace', async () => {
const browser = await webdriver(
context.appPort,
`/absolute-url?port=${context.appPort}`
)
await browser.eval(() => (window._didNotNavigate = true))
await browser.waitForElementByCss('#router-local-replace').click()
const text = await browser
.waitForElementByCss('.nav-about')
.elementByCss('p')
.text()
expect(text).toBe('This is the about page.')
expect(await browser.eval(() => window._didNotNavigate)).toBe(true)
})
}) })
describe('with next/link', () => { describe('with next/link', () => {
......
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
const invalidLink = 'https://google.com/another' const invalidLink = 'https://vercel.com/solutions/nextjs'
export default function Page() { export default function Page() {
const { query, ...router } = useRouter() const { query, ...router } = useRouter()
......
import { useRouter } from 'next/router' import Link from 'next/link'
import { useState } from 'react' const invalidLink = 'https://'
const invalidLink = 'https://vercel.com/'
export default function Page() { export default function Page() {
const { query, ...router } = useRouter()
const [isDone, setIsDone] = useState(false)
const { method = 'push' } = query
function click(e) {
router[method](invalidLink).then(
() => setIsDone(true),
() => setIsDone(true)
)
}
return ( return (
<> <Link href={invalidLink}>
<button id="click-me" onClick={click}> <a id="click-me">invalid link :o</a>
Click me </Link>
</button>
{isDone ? <div id="is-done">Done</div> : null}
</>
) )
} }
...@@ -10,7 +10,9 @@ import { ...@@ -10,7 +10,9 @@ import {
nextStart, nextStart,
waitFor, waitFor,
check, check,
fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
...@@ -20,9 +22,6 @@ let app ...@@ -20,9 +22,6 @@ let app
let appPort let appPort
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
const firstErrorRegex = /Invalid href passed to router: mailto:idk@idk.com.*invalid-href-passed/
const secondErrorRegex = /Invalid href passed to router: .*google\.com.*invalid-href-passed/
// This test doesn't seem to benefit from retries, let's disable them until the test gets fixed // This test doesn't seem to benefit from retries, let's disable them until the test gets fixed
// to prevent long running times // to prevent long running times
jest.retryTimes(0) jest.retryTimes(0)
...@@ -99,26 +98,10 @@ describe('Invalid hrefs', () => { ...@@ -99,26 +98,10 @@ describe('Invalid hrefs', () => {
await noError('/first') await noError('/first')
}) })
it('does not show error in production when mailto: is used as href on router.push', async () => {
await noError('/first?method=push', true)
})
it('does not show error in production when mailto: is used as href on router.replace', async () => {
await noError('/first?method=replace', true)
})
it('does not show error in production when https://google.com is used as href on Link', async () => { it('does not show error in production when https://google.com is used as href on Link', async () => {
await noError('/second') await noError('/second')
}) })
it('does not show error in production when http://google.com is used as href on router.push', async () => {
await noError('/second?method=push', true)
})
it('does not show error in production when https://google.com is used as href on router.replace', async () => {
await noError('/second?method=replace', true)
})
it('shows error when dynamic route mismatch is used on Link', async () => { it('shows error when dynamic route mismatch is used on Link', async () => {
const browser = await webdriver(appPort, '/dynamic-route-mismatch') const browser = await webdriver(appPort, '/dynamic-route-mismatch')
try { try {
...@@ -143,16 +126,14 @@ describe('Invalid hrefs', () => { ...@@ -143,16 +126,14 @@ describe('Invalid hrefs', () => {
} }
}) })
it('makes sure that router push with bad links resolve', async () => { it("doesn't fail on invalid url", async () => {
const browser = await webdriver(appPort, '/third') await noError('/third')
await browser.elementByCss('#click-me').click()
await browser.waitForElementByCss('#is-done')
}) })
it('makes sure that router replace with bad links resolve', async () => { it('renders a link with invalid href', async () => {
const browser = await webdriver(appPort, '/third?method=replace') const res = await fetchViaHTTP(appPort, '/third')
await browser.elementByCss('#click-me').click() const $ = cheerio.load(await res.text())
await browser.waitForElementByCss('#is-done') expect($('#click-me').attr('href')).toBe('https://')
}) })
}) })
...@@ -163,28 +144,12 @@ describe('Invalid hrefs', () => { ...@@ -163,28 +144,12 @@ describe('Invalid hrefs', () => {
}) })
afterAll(() => killApp(app)) afterAll(() => killApp(app))
it('shows error when mailto: is used as href on Link', async () => { it('does not show error when mailto: is used as href on Link', async () => {
await showsError('/first', firstErrorRegex) await noError('/first')
})
it('shows error when mailto: is used as href on router.push', async () => {
await showsError('/first?method=push', firstErrorRegex, true)
})
it('shows error when mailto: is used as href on router.replace', async () => {
await showsError('/first?method=replace', firstErrorRegex, true)
})
it('shows error when https://google.com is used as href on Link', async () => {
await showsError('/second', secondErrorRegex)
})
it('shows error when http://google.com is used as href on router.push', async () => {
await showsError('/second?method=push', secondErrorRegex, true)
}) })
it('shows error when https://google.com is used as href on router.replace', async () => { it('does not show error when https://google.com is used as href on Link', async () => {
await showsError('/second?method=replace', secondErrorRegex, true) await noError('/second')
}) })
it('shows error when dynamic route mismatch is used on Link', async () => { it('shows error when dynamic route mismatch is used on Link', async () => {
...@@ -199,6 +164,10 @@ describe('Invalid hrefs', () => { ...@@ -199,6 +164,10 @@ describe('Invalid hrefs', () => {
await noError('/dynamic-route-mismatch-manual', true) await noError('/dynamic-route-mismatch-manual', true)
}) })
it("doesn't fail on invalid url", async () => {
await noError('/third')
})
it('shows warning when dynamic route mismatch is used on Link', async () => { it('shows warning when dynamic route mismatch is used on Link', async () => {
await showsError( await showsError(
'/dynamic-route-mismatch', '/dynamic-route-mismatch',
......
...@@ -100,7 +100,7 @@ describe('Production response size', () => { ...@@ -100,7 +100,7 @@ describe('Production response size', () => {
) )
// These numbers are without gzip compression! // These numbers are without gzip compression!
const delta = responseSizesBytes - 166 * 1024 const delta = responseSizesBytes - 167 * 1024
expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
}) })
......
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