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

feat(experimental): option to polyfill fetch using undici in Node.js <18 #40318

Merged
merged 61 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
66408d8
polyfill undici
Sep 7, 2022
28a09b8
move polyfill to inside !global.fetch
Sep 7, 2022
0daf850
remove nodejs type update
Sep 7, 2022
1c5c027
update types and compile undici
Sep 7, 2022
f4169d7
try using global.__NEXT_USE_UNDICI and add tests
Sep 9, 2022
0b2475a
Merge branch 'canary' of github.com:vercel/next.js into feature/polyf…
Sep 9, 2022
07be524
remove auto-generated files
Sep 9, 2022
32d3677
Merge branch 'canary' of github.com:vercel/next.js into feature/polyf…
Sep 14, 2022
4cbc65f
Add ?. to useUndici
Sep 14, 2022
eb44e6b
Fix global config resolution
Sep 14, 2022
7fd115a
Fix global properties and add more tests
Sep 14, 2022
2a962a4
Update function name
Sep 15, 2022
6593733
remove unused code
Sep 15, 2022
a11d117
require fetch implementation conditionally
balazsorban44 Sep 15, 2022
ebc33d7
update lock file
balazsorban44 Sep 15, 2022
f623f65
add `keepAlive` tests for `undici`
balazsorban44 Sep 15, 2022
502db7f
handle `keepAlive` with `undici`
balazsorban44 Sep 15, 2022
88c65cd
Merge branch 'canary' into feature/polyfill-undici-fetch
balazsorban44 Sep 15, 2022
1651916
update compiled
balazsorban44 Sep 15, 2022
8393aaf
Merge branch 'feature/polyfill-undici-fetch' of github.com:Ethan-Arro…
balazsorban44 Sep 15, 2022
76d7b6c
Merge branch 'canary' into feature/polyfill-undici-fetch
Sep 15, 2022
367862f
add back `mini-css-extract-plugin` compiled
balazsorban44 Sep 16, 2022
3866700
revert compiled
balazsorban44 Sep 16, 2022
58ecb4c
Merge branch 'canary' into feature/polyfill-undici-fetch
balazsorban44 Sep 16, 2022
454d917
revert webpack compiled changes
balazsorban44 Sep 16, 2022
1b26d54
Merge branch 'feature/polyfill-undici-fetch' of github.com:Ethan-Arro…
balazsorban44 Sep 16, 2022
0de1fb4
revert
balazsorban44 Sep 16, 2022
ec21630
revert
balazsorban44 Sep 16, 2022
e8550fa
revert?
balazsorban44 Sep 16, 2022
7e6b1f9
more revert
balazsorban44 Sep 16, 2022
4919546
one more
balazsorban44 Sep 16, 2022
ef8b44f
update taskfile
balazsorban44 Sep 16, 2022
789b43b
update compiled
balazsorban44 Sep 16, 2022
245ff7b
Add version guard for <16.8.0
Sep 16, 2022
60d99d7
fix lock file
Sep 16, 2022
0de3c26
Update packages/next/server/config.ts
Ethan-Arrowood Sep 16, 2022
989f9c8
fix semver usage
Sep 16, 2022
ed03b2b
useUndici -> enableUndici
Sep 16, 2022
421891b
Merge branch 'canary' into feature/polyfill-undici-fetch
Sep 16, 2022
acf39cb
Merge branch 'canary' of github.com:vercel/next.js into feature/polyf…
Sep 19, 2022
203c3e7
Merge branch 'feature/polyfill-undici-fetch' of github.com:Ethan-Arro…
Sep 19, 2022
bbc2ac5
fix lock file
Sep 19, 2022
cbafb7f
Merge branch 'canary' into feature/polyfill-undici-fetch
Sep 19, 2022
d2087ce
Merge branch 'canary' into feature/polyfill-undici-fetch
ijjk Sep 21, 2022
f770bd5
update lock
ijjk Sep 21, 2022
31beccc
update compiled
ijjk Sep 21, 2022
7722ea5
Update packages/next/server/node-polyfill-fetch.js
Ethan-Arrowood Sep 21, 2022
424531a
add enableUndici to worker exportPage
Sep 21, 2022
7da8b81
Merge branch 'canary' of github.com:vercel/next.js into feature/polyf…
Sep 26, 2022
72c90fe
add missing argument in exportPage and revert compiled file changes
Sep 26, 2022
e5f3c60
remove compiled sass-loader file
Sep 26, 2022
fbc3e4d
Merge branch 'canary' into feature/polyfill-undici-fetch
Sep 26, 2022
fcfa989
update lock file
balazsorban44 Sep 26, 2022
08fefca
Merge branch 'canary' into feature/polyfill-undici-fetch
balazsorban44 Sep 26, 2022
b101ec6
update compiled
balazsorban44 Sep 26, 2022
82a0961
fix test
balazsorban44 Sep 26, 2022
ef18f28
tweak `enableUndici` warnings
balazsorban44 Sep 27, 2022
05ca18f
pass `enableUndici` to worker
balazsorban44 Sep 27, 2022
519c717
tweak test
balazsorban44 Sep 27, 2022
6002dba
Merge branch 'canary' into feature/polyfill-undici-fetch
ijjk Sep 27, 2022
8ed03ee
Merge branch 'canary' into feature/polyfill-undici-fetch
ijjk Sep 27, 2022
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
Prev Previous commit
Next Next commit
add keepAlive tests for undici
  • Loading branch information
balazsorban44 committed Sep 15, 2022
commit f623f65ee7f59908ff27eb297b859cf105141ac5
5 changes: 5 additions & 0 deletions test/integration/undici-keep-alive/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
useUndici: true,
},
}
5 changes: 5 additions & 0 deletions test/integration/undici-keep-alive/pages/api/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async function handler(_req, res) {
const fetchRes = await fetch('http://localhost:44001')
const props = await fetchRes.json()
res.json(props)
}
23 changes: 23 additions & 0 deletions test/integration/undici-keep-alive/pages/blog/[slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default function Blog(props) {
return <pre id="props">{JSON.stringify(props)}</pre>
}

export async function getStaticProps({ params: { slug } }) {
return { props: { slug } }
}

export async function getStaticPaths() {
const res = await fetch('http://localhost:44001')
const obj = await res.json()
if (obj.connection === 'keep-alive') {
return {
paths: [{ params: { slug: 'first' } }],
fallback: false,
}
}

return {
paths: [],
fallback: false,
}
}
9 changes: 9 additions & 0 deletions test/integration/undici-keep-alive/pages/ssg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function SSG(props) {
return <pre id="props">{JSON.stringify(props)}</pre>
}

export async function getStaticProps() {
const res = await fetch('http://localhost:44001')
const props = await res.json()
return { props }
}
9 changes: 9 additions & 0 deletions test/integration/undici-keep-alive/pages/ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function SSR(props) {
return <pre id="props">{JSON.stringify(props)}</pre>
}

export async function getServerSideProps() {
const res = await fetch('http://localhost:44001')
const props = await res.json()
return { props }
}
99 changes: 99 additions & 0 deletions test/integration/undici-keep-alive/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-env jest */

import { join } from 'path'
import { createServer } from 'http'
import {
fetchViaHTTP,
nextBuild,
findPort,
nextStart,
launchApp,
killApp,
} from 'next-test-utils'
import webdriver from 'next-webdriver'

const appDir = join(__dirname, '../')

let appPort
let app
let mockServer

describe('undici-keep-alive', () => {
describe('dev', () => {
beforeAll(async () => {
mockServer = createServer((req, res) => {
// we can test request headers by sending them
// back with the response
const { connection } = req.headers
res.end(JSON.stringify({ connection }))
})
mockServer.listen(44001)
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
mockServer.close()
})

runTests()
})

describe('production', () => {
beforeAll(async () => {
mockServer = createServer((req, res) => {
// we can test request headers by sending them
// back with the response
const { connection } = req.headers
res.end(JSON.stringify({ connection }))
})
mockServer.listen(44001)
const { stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
if (stdout) console.log(stdout)
if (stderr) console.error(stderr)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
mockServer.close()
})

runTests()
})

function runTests() {
it('should send keep-alive for json API', async () => {
const res = await fetchViaHTTP(appPort, '/api/json')
const obj = await res.json()
expect(obj).toEqual({ connection: 'keep-alive' })
})

it('should send keep-alive for getStaticProps', async () => {
const browser = await webdriver(appPort, '/ssg')
const props = await browser.elementById('props').text()
const obj = JSON.parse(props)
expect(obj).toEqual({ connection: 'keep-alive' })
await browser.close()
})

it('should send keep-alive for getStaticPaths', async () => {
const browser = await webdriver(appPort, '/blog/first')
const props = await browser.elementById('props').text()
const obj = JSON.parse(props)
expect(obj).toEqual({ slug: 'first' })
await browser.close()
})

it('should send keep-alive for getServerSideProps', async () => {
const browser = await webdriver(appPort, '/ssr')
const props = await browser.elementById('props').text()
const obj = JSON.parse(props)
expect(obj).toEqual({ connection: 'keep-alive' })
await browser.close()
})
}
})