Skip to content

Commit

Permalink
Remove unnecessary unfetch polyfill for dev (#20589)
Browse files Browse the repository at this point in the history
Fetch is always polyfilled in legacy browsers by `@next/polyfill-nomodule`, so we do not need to import unfetch for IE11 support.

Fixes #20588
  • Loading branch information
Timer authored Dec 29, 2020
1 parent 61e7dea commit 52270af
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/next/client/dev/amp-dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals __webpack_hash__ */
import fetch from 'next/dist/build/polyfills/unfetch'
import EventSourcePolyfill from './event-source-polyfill'
import { getEventSourceWrapper } from './error-overlay/eventsource'
import { setupPing } from './on-demand-entries-utils'
Expand Down
2 changes: 0 additions & 2 deletions packages/next/client/dev/event-source-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Improved version of https://github.com/Yaffle/EventSource/
// Available under MIT License (MIT)
// Only tries to support IE11 and nothing below
import fetch from 'next/dist/build/polyfills/unfetch'

var document = window.document
var Response = window.Response
var TextDecoder = window.TextDecoder
Expand Down
2 changes: 0 additions & 2 deletions packages/next/client/dev/on-demand-entries-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global location */

import fetch from 'next/dist/build/polyfills/unfetch'
import { getEventSourceWrapper } from './error-overlay/eventsource'

let evtSource
Expand Down
1 change: 0 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
"text-table": "0.2.0",
"thread-loader": "2.1.3",
"typescript": "3.8.3",
"unfetch": "4.1.0",
"unistore": "3.4.1",
"web-vitals": "0.2.4"
},
Expand Down
1 change: 1 addition & 0 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ export class NextScript extends Component<OriginProps> {

const ampDevFiles = [
...buildManifest.devFiles,
...buildManifest.polyfillFiles,
...buildManifest.ampDevFiles,
]

Expand Down
8 changes: 1 addition & 7 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ export async function next__polyfill_nomodule(task, opts) {
.target('dist/build/polyfills')
}

export async function unfetch(task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('unfetch')))
.target('dist/build/polyfills')
}

export async function browser_polyfills(task) {
await task.parallel(['next__polyfill_nomodule', 'unfetch'])
await task.parallel(['next__polyfill_nomodule'])
}

const externals = {
Expand Down
1 change: 0 additions & 1 deletion packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ declare module 'cssnano-simple' {
export = cssnanoSimple
}
declare module 'styled-jsx/server'
declare module 'unfetch'
declare module 'webpack/lib/GraphHelpers'
declare module 'webpack/lib/DynamicEntryPlugin'
declare module 'webpack/lib/Entrypoint'
Expand Down
15 changes: 14 additions & 1 deletion test/integration/amphtml/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,20 @@ describe('AMP Usage', () => {
const html = await renderViaHTTP(dynamicAppPort, '/only-amp')
const $ = cheerio.load(html)
expect($('html').attr('data-ampdevmode')).toBe('')
expect($('script[data-ampdevmode]').length).toBe(4)
expect(
[].slice
.apply($('script[data-ampdevmode]'))
.map((el) => el.attribs.src || el.attribs.id)
.map((e) =>
e.startsWith('/') ? new URL(e, 'http://x.x').pathname : e
)
).toEqual([
'__NEXT_DATA__',
'/_next/static/chunks/react-refresh.js',
'/_next/static/chunks/polyfills.js',
'/_next/static/chunks/webpack.js',
'/_next/static/chunks/amp.js',
])
})

it('should detect the changes and display it', async () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15475,7 +15475,7 @@ umask@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/umask/-/umask-1.1.0.tgz#f29cebf01df517912bb58ff9c4e50fde8e33320d"

unfetch@4.1.0, unfetch@^4.0.0:
unfetch@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"

Expand Down

0 comments on commit 52270af

Please sign in to comment.