Unverified Commit 00f8297c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix prefetching in IE11 (#19171)

Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent f0d2e643
...@@ -58,9 +58,8 @@ ...@@ -58,9 +58,8 @@
"babel-core": "7.0.0-bridge.0", "babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.3", "babel-eslint": "10.0.3",
"babel-jest": "24.9.0", "babel-jest": "24.9.0",
"browserslist": "^4.14.6", "browserslist": "^4.14.7",
"browserstack-local": "1.4.0", "browserstack-local": "1.4.0",
"caniuse-lite": "^1.0.30001019",
"cheerio": "0.22.0", "cheerio": "0.22.0",
"clone": "2.1.2", "clone": "2.1.2",
"cookie": "0.4.1", "cookie": "0.4.1",
...@@ -130,8 +129,8 @@ ...@@ -130,8 +129,8 @@
"worker-loader": "2.0.0" "worker-loader": "2.0.0"
}, },
"resolutions": { "resolutions": {
"browserslist": "^4.14.6", "browserslist": "^4.14.7",
"caniuse-lite": "^1.0.30001019" "caniuse-lite": "^1.0.30001157"
}, },
"engines": { "engines": {
"node": ">= 10.13.0" "node": ">= 10.13.0"
......
...@@ -75,7 +75,12 @@ export interface RouteLoader { ...@@ -75,7 +75,12 @@ export interface RouteLoader {
function hasPrefetch(link?: HTMLLinkElement): boolean { function hasPrefetch(link?: HTMLLinkElement): boolean {
try { try {
link = document.createElement('link') 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 { } catch {
return false return false
} }
......
...@@ -24,7 +24,7 @@ export async function browser_polyfills(task) { ...@@ -24,7 +24,7 @@ export async function browser_polyfills(task) {
const externals = { const externals = {
// Browserslist (post-css plugins) // Browserslist (post-css plugins)
browserslist: 'browserslist', browserslist: 'browserslist',
'caniuse-lite': 'caniuse-lite', 'caniuse-lite': 'caniuse-lite', // FIXME: `autoprefixer` will still bundle this because it uses direct imports
chalk: 'chalk', chalk: 'chalk',
'node-fetch': 'node-fetch', 'node-fetch': 'node-fetch',
......
...@@ -95,7 +95,7 @@ describe('Build Output', () => { ...@@ -95,7 +95,7 @@ describe('Build Output', () => {
expect(indexSize.endsWith('B')).toBe(true) expect(indexSize.endsWith('B')).toBe(true)
// should be no bigger than 61.8 kb // 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(indexFirstLoad.endsWith('kB')).toBe(true)
expect(parseFloat(err404Size) - 3.6).toBeLessThanOrEqual(0) expect(parseFloat(err404Size) - 3.6).toBeLessThanOrEqual(0)
......
...@@ -163,7 +163,7 @@ describe('CSS Support', () => { ...@@ -163,7 +163,7 @@ describe('CSS Support', () => {
expect( expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim() cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot( ).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 // Contains a source map
...@@ -184,7 +184,7 @@ describe('CSS Support', () => { ...@@ -184,7 +184,7 @@ describe('CSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object { 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 [ "sourcesContent": Array [
"@media (480px <= width < 768px) { "@media (480px <= width < 768px) {
::placeholder { ::placeholder {
......
...@@ -63,7 +63,20 @@ const runTests = () => { ...@@ -63,7 +63,20 @@ const runTests = () => {
expect(props2.found).toBe(true) expect(props2.found).toBe(true)
expect(props2.params).toEqual({ slug: 'hello' }) expect(props2.params).toEqual({ slug: 'hello' })
expect(isNaN(props2.random)).toBe(false) 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 () => { it('should revalidate after notFound is returned for fallback: true', async () => {
...@@ -106,7 +119,20 @@ const runTests = () => { ...@@ -106,7 +119,20 @@ const runTests = () => {
expect(props2.found).toBe(true) expect(props2.found).toBe(true)
expect(props2.params).toEqual({ slug: 'world' }) expect(props2.params).toEqual({ slug: 'world' })
expect(isNaN(props2.random)).toBe(false) 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)
}) })
} }
......
...@@ -248,7 +248,7 @@ describe('SCSS Support', () => { ...@@ -248,7 +248,7 @@ describe('SCSS Support', () => {
expect( expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim() cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot( ).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 // Contains a source map
...@@ -269,7 +269,7 @@ describe('SCSS Support', () => { ...@@ -269,7 +269,7 @@ describe('SCSS Support', () => {
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent) const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(` expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
Object { 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 [ "sourcesContent": Array [
"$var: red; "$var: red;
.redText { .redText {
......
...@@ -4122,15 +4122,16 @@ browserify-zlib@^0.2.0: ...@@ -4122,15 +4122,16 @@ browserify-zlib@^0.2.0:
dependencies: dependencies:
pako "~1.0.5" 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: 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.6" version "4.14.7"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.6.tgz#97702a9c212e0c6b6afefad913d3a1538e348457" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.7.tgz#c071c1b3622c1c2e790799a37bb09473a4351cb6"
integrity sha512-zeFYcUo85ENhc/zxHbiIp0LGzzTrE2Pv2JhxvS7kpUb9Q9D38kUX6Bie7pGutJ/5iF5rOxE7CepAuWD56xJ33A== integrity sha512-BSVRLCeG3Xt/j/1cCGj1019Wbty0H+Yvu2AOuZSuoaUWn3RatbL33Cxk+Q4jRMRAbOm0p7SLravLjpnT6s0vzQ==
dependencies: dependencies:
caniuse-lite "^1.0.30001154" caniuse-lite "^1.0.30001157"
electron-to-chromium "^1.3.585" colorette "^1.2.1"
electron-to-chromium "^1.3.591"
escalade "^3.1.1" escalade "^3.1.1"
node-releases "^1.1.65" node-releases "^1.1.66"
browserstack-local@1.4.0: browserstack-local@1.4.0:
version "1.4.0" version "1.4.0"
...@@ -4443,10 +4444,10 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634: ...@@ -4443,10 +4444,10 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634:
version "1.0.30001023" version "1.0.30001023"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30001023.tgz#f856f71af16a5a44e81f1fcefc1673912a43da72" 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: 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.30001066" version "1.0.30001157"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04" resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz"
integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw== integrity sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA==
capitalize@1.0.0: capitalize@1.0.0:
version "1.0.0" version "1.0.0"
...@@ -6259,10 +6260,10 @@ ejs@^2.6.1: ...@@ -6259,10 +6260,10 @@ ejs@^2.6.1:
version "2.7.4" version "2.7.4"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba"
electron-to-chromium@^1.3.585: electron-to-chromium@^1.3.591:
version "1.3.588" version "1.3.596"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.588.tgz#c6515571737bfb42678115a5eaa818384593a9a5" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.596.tgz#c7ed98512c7ff36ddcbfed9e54e6355335c35257"
integrity sha512-0zr+ZfytnLeJZxGgmEpPTcItu5Mm4A5zHPZXLfHcGp0mdsk95rmD7ePNewYtK1yIdLbk8Z1U2oTRRfOtR4gbYg== integrity sha512-nLO2Wd2yU42eSoNJVQKNf89CcEGqeFZd++QsnN2XIgje1s/19AgctfjLIbPORlvcCO8sYjLwX4iUgDdusOY8Sg==
elegant-spinner@^1.0.1: elegant-spinner@^1.0.1:
version "1.0.1" version "1.0.1"
...@@ -11155,10 +11156,10 @@ node-notifier@^5.4.2: ...@@ -11155,10 +11156,10 @@ node-notifier@^5.4.2:
shellwords "^0.1.1" shellwords "^0.1.1"
which "^1.3.0" which "^1.3.0"
node-releases@^1.1.65: node-releases@^1.1.66:
version "1.1.65" version "1.1.66"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.65.tgz#52d9579176bd60f23eba05c4438583f341944b81" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.66.tgz#609bd0dc069381015cd982300bae51ab4f1b1814"
integrity sha512-YpzJOe2WFIW0V4ZkJQd/DGR/zdVwc/pI4Nl1CZrBO19FdRcSTmsuhdttw9rsTzzJLrNcSloLiBbEYx1C4f6gpA== integrity sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg==
node-sass@5.0.0: node-sass@5.0.0:
version "5.0.0" version "5.0.0"
......
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