Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prefetching in IE11 #19171

Merged
merged 10 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.3",
"babel-jest": "24.9.0",
"browserslist": "^4.14.6",
"browserslist": "^4.14.7",
"browserstack-local": "1.4.0",
"caniuse-lite": "^1.0.30001019",
"cheerio": "0.22.0",
"clone": "2.1.2",
"cookie": "0.4.1",
Expand Down Expand Up @@ -130,8 +129,8 @@
"worker-loader": "2.0.0"
},
"resolutions": {
"browserslist": "^4.14.6",
"caniuse-lite": "^1.0.30001019"
"browserslist": "^4.14.7",
"caniuse-lite": "^1.0.30001157"
},
"engines": {
"node": ">= 10.13.0"
Expand Down
7 changes: 6 additions & 1 deletion packages/next/client/route-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export interface RouteLoader {
function hasPrefetch(link?: HTMLLinkElement): boolean {
try {
link = document.createElement('link')
return link.relList.supports('prefetch')
return (
// detect IE11 since it supports prefetch but isn't detected
// with relList.support
(!!window.MSInputMethodContext && !!(document as any).documentMode) ||
link.relList.supports('prefetch')
)
} catch {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/postcss-preset-env/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function browser_polyfills(task) {
const externals = {
// Browserslist (post-css plugins)
browserslist: 'browserslist',
'caniuse-lite': 'caniuse-lite',
'caniuse-lite': 'caniuse-lite', // FIXME: `autoprefixer` will still bundle this because it uses direct imports

chalk: 'chalk',
'node-fetch': 'node-fetch',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/build-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Build Output', () => {
expect(indexSize.endsWith('B')).toBe(true)

// should be no bigger than 61.8 kb
expect(parseFloat(indexFirstLoad) - 61.8).toBeLessThanOrEqual(0)
expect(parseFloat(indexFirstLoad) - 61.9).toBeLessThanOrEqual(0)
expect(indexFirstLoad.endsWith('kB')).toBe(true)

expect(parseFloat(err404Size) - 3.6).toBeLessThanOrEqual(0)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/css/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('CSS Support', () => {
expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot(
`"@media (min-width:480px) and (max-width:767px){::-moz-placeholder{color:green}:-ms-input-placeholder{color:green}::-ms-input-placeholder{color:green}::placeholder{color:green}}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}.transform-parsing{transform:translate3d(0,0)}.css-grid-shorthand{grid-column:span 2}.g-docs-sidenav .filter::-webkit-input-placeholder{opacity:80%}"`
`"@media (min-width:480px) and (max-width:767px){::-moz-placeholder{color:green}:-ms-input-placeholder{color:green}::placeholder{color:green}}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}.transform-parsing{transform:translate3d(0,0)}.css-grid-shorthand{grid-column:span 2}.g-docs-sidenav .filter::-webkit-input-placeholder{opacity:80%}"`
)

// Contains a source map
Expand All @@ -184,7 +184,7 @@ describe('CSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object {
"mappings": "AAAA,+CACE,mBACE,WACF,CAFA,uBACE,WACF,CAFA,wBACE,WACF,CAFA,cACE,WACF,CACF,CAEA,cACE,2CACF,CAEA,mBACE,0BACF,CAEA,oBACE,kBACF,CAEA,mDACE,WACF",
"mappings": "AAAA,+CACE,mBACE,WACF,CAFA,uBACE,WACF,CAFA,cACE,WACF,CACF,CAEA,cACE,2CACF,CAEA,mBACE,0BACF,CAEA,oBACE,kBACF,CAEA,mDACE,WACF",
"sourcesContent": Array [
"@media (480px <= width < 768px) {
::placeholder {
Expand Down
30 changes: 28 additions & 2 deletions test/integration/not-found-revalidate/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ const runTests = () => {
expect(props2.found).toBe(true)
expect(props2.params).toEqual({ slug: 'hello' })
expect(isNaN(props2.random)).toBe(false)
expect(props2.random).not.toBe(props.random)

await waitFor(1000)
res = await fetchViaHTTP(appPort, '/fallback-blocking/hello')
$ = cheerio.load(await res.text())

const props3 = JSON.parse($('#props').text())
expect(res.headers.get('cache-control')).toBe(
's-maxage=1, stale-while-revalidate'
)
expect(res.status).toBe(200)
expect(props3.found).toBe(true)
expect(props3.params).toEqual({ slug: 'hello' })
expect(isNaN(props3.random)).toBe(false)
expect(props3.random).not.toBe(props.random)
})

it('should revalidate after notFound is returned for fallback: true', async () => {
Expand Down Expand Up @@ -106,7 +119,20 @@ const runTests = () => {
expect(props2.found).toBe(true)
expect(props2.params).toEqual({ slug: 'world' })
expect(isNaN(props2.random)).toBe(false)
expect(props2.random).not.toBe(props.random)

await waitFor(1000)
res = await fetchViaHTTP(appPort, '/fallback-true/world')
$ = cheerio.load(await res.text())

const props3 = JSON.parse($('#props').text())
expect(res.headers.get('cache-control')).toBe(
's-maxage=1, stale-while-revalidate'
)
expect(res.status).toBe(200)
expect(props3.found).toBe(true)
expect(props3.params).toEqual({ slug: 'world' })
expect(isNaN(props3.random)).toBe(false)
expect(props3.random).not.toBe(props.random)
})
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/scss/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('SCSS Support', () => {
expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot(
`".redText ::-moz-placeholder{color:red}.redText :-ms-input-placeholder{color:red}.redText ::-ms-input-placeholder{color:red}.redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
`".redText ::-moz-placeholder{color:red}.redText :-ms-input-placeholder{color:red}.redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)

// Contains a source map
Expand All @@ -269,7 +269,7 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object {
"mappings": "AACA,4BAEI,SAHK,CACT,gCAEI,SAHK,CACT,iCAEI,SAHK,CACT,uBAEI,SAHK,CAIN,cAID,2CAA4C",
"mappings": "AACA,4BAEI,SAHK,CACT,gCAEI,SAHK,CACT,uBAEI,SAHK,CAIN,cAID,2CAA4C",
"sourcesContent": Array [
"$var: red;
.redText {
Expand Down
39 changes: 20 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4122,15 +4122,16 @@ browserify-zlib@^0.2.0:
dependencies:
pako "~1.0.5"

browserslist@4.14.6, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.6, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5:
version "4.14.6"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.6.tgz#97702a9c212e0c6b6afefad913d3a1538e348457"
integrity sha512-zeFYcUo85ENhc/zxHbiIp0LGzzTrE2Pv2JhxvS7kpUb9Q9D38kUX6Bie7pGutJ/5iF5rOxE7CepAuWD56xJ33A==
browserslist@4.14.6, browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.14.7, browserslist@^4.3.6, browserslist@^4.6.4, browserslist@^4.8.3, browserslist@^4.8.5:
version "4.14.7"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.7.tgz#c071c1b3622c1c2e790799a37bb09473a4351cb6"
integrity sha512-BSVRLCeG3Xt/j/1cCGj1019Wbty0H+Yvu2AOuZSuoaUWn3RatbL33Cxk+Q4jRMRAbOm0p7SLravLjpnT6s0vzQ==
dependencies:
caniuse-lite "^1.0.30001154"
electron-to-chromium "^1.3.585"
caniuse-lite "^1.0.30001157"
colorette "^1.2.1"
electron-to-chromium "^1.3.591"
escalade "^3.1.1"
node-releases "^1.1.65"
node-releases "^1.1.66"

browserstack-local@1.4.0:
version "1.4.0"
Expand Down Expand Up @@ -4443,10 +4444,10 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634:
version "1.0.30001023"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001023.tgz#f856f71af16a5a44e81f1fcefc1673912a43da72"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001019, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001113, caniuse-lite@^1.0.30001154:
version "1.0.30001066"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04"
integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001113, caniuse-lite@^1.0.30001157:
version "1.0.30001157"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz"
integrity sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA==

capitalize@1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -6259,10 +6260,10 @@ ejs@^2.6.1:
version "2.7.4"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"

electron-to-chromium@^1.3.585:
version "1.3.588"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.588.tgz#c6515571737bfb42678115a5eaa818384593a9a5"
integrity sha512-0zr+ZfytnLeJZxGgmEpPTcItu5Mm4A5zHPZXLfHcGp0mdsk95rmD7ePNewYtK1yIdLbk8Z1U2oTRRfOtR4gbYg==
electron-to-chromium@^1.3.591:
version "1.3.596"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.596.tgz#c7ed98512c7ff36ddcbfed9e54e6355335c35257"
integrity sha512-nLO2Wd2yU42eSoNJVQKNf89CcEGqeFZd++QsnN2XIgje1s/19AgctfjLIbPORlvcCO8sYjLwX4iUgDdusOY8Sg==

elegant-spinner@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -11155,10 +11156,10 @@ node-notifier@^5.4.2:
shellwords "^0.1.1"
which "^1.3.0"

node-releases@^1.1.65:
version "1.1.65"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.65.tgz#52d9579176bd60f23eba05c4438583f341944b81"
integrity sha512-YpzJOe2WFIW0V4ZkJQd/DGR/zdVwc/pI4Nl1CZrBO19FdRcSTmsuhdttw9rsTzzJLrNcSloLiBbEYx1C4f6gpA==
node-releases@^1.1.66:
version "1.1.66"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.66.tgz#609bd0dc069381015cd982300bae51ab4f1b1814"
integrity sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg==

node-sass@5.0.0:
version "5.0.0"
Expand Down