Unverified Commit 889af9fd authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix edge workers being re-used unexpectedly (#41402)

This ensures we don't re-use edge workers locally as they are meant to
be isolated.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

Fixes: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1665708744315109)
parent 241195dd
...@@ -1800,7 +1800,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -1800,7 +1800,7 @@ export default class NextNodeServer extends BaseServer {
page: page, page: page,
body: getRequestMeta(params.request, '__NEXT_CLONABLE_BODY'), body: getRequestMeta(params.request, '__NEXT_CLONABLE_BODY'),
}, },
useCache: !this.nextConfig.experimental.runtime, useCache: false,
onWarning: params.onWarning, onWarning: params.onWarning,
}) })
...@@ -2126,7 +2126,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -2126,7 +2126,7 @@ export default class NextNodeServer extends BaseServer {
}, },
body: getRequestMeta(params.req, '__NEXT_CLONABLE_BODY'), body: getRequestMeta(params.req, '__NEXT_CLONABLE_BODY'),
}, },
useCache: !this.nextConfig.experimental.runtime, useCache: false,
onWarning: params.onWarning, onWarning: params.onWarning,
}) })
......
...@@ -314,15 +314,8 @@ interface ModuleContextOptions { ...@@ -314,15 +314,8 @@ interface ModuleContextOptions {
edgeFunctionEntry: Pick<EdgeFunctionDefinition, 'assets' | 'wasm'> edgeFunctionEntry: Pick<EdgeFunctionDefinition, 'assets' | 'wasm'>
} }
const pendingModuleCaches = new Map<string, Promise<ModuleContext>>()
function getModuleContextShared(options: ModuleContextOptions) { function getModuleContextShared(options: ModuleContextOptions) {
let deferredModuleContext = pendingModuleCaches.get(options.moduleName) return createModuleContext(options)
if (!deferredModuleContext) {
deferredModuleContext = createModuleContext(options)
pendingModuleCaches.set(options.moduleName, deferredModuleContext)
}
return deferredModuleContext
} }
/** /**
......
import { experimental_use as use } from 'react'
async function getData() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
message: 'hello from slow page',
}
}
export default function SlowPage(props) {
const data = use(getData())
return <h1 id="slow-page-message">{data.message}</h1>
}
export const config = {
runtime: 'experimental-edge',
}
...@@ -42,6 +42,35 @@ describe('app dir', () => { ...@@ -42,6 +42,35 @@ describe('app dir', () => {
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('should not share edge workers', async () => {
const controller1 = new AbortController()
const controller2 = new AbortController()
fetchViaHTTP(next.url, '/slow-page-no-loading', undefined, {
signal: controller1.signal,
}).catch(() => {})
fetchViaHTTP(next.url, '/slow-page-no-loading', undefined, {
signal: controller2.signal,
}).catch(() => {})
await waitFor(1000)
controller1.abort()
const controller3 = new AbortController()
fetchViaHTTP(next.url, '/slow-page-no-loading', undefined, {
signal: controller3.signal,
}).catch(() => {})
await waitFor(1000)
controller2.abort()
controller3.abort()
const res = await fetchViaHTTP(next.url, '/slow-page-no-loading')
expect(res.status).toBe(200)
expect(await res.text()).toContain('hello from slow page')
expect(next.cliOutput).not.toContain(
'A separate worker must be used for each render'
)
})
if ((global as any).isNextStart) { if ((global as any).isNextStart) {
it('should generate build traces correctly', async () => { it('should generate build traces correctly', async () => {
const trace = JSON.parse( const trace = JSON.parse(
......
import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export default function Page(props) { export default function Page(props) {
...@@ -5,7 +6,19 @@ export default function Page(props) { ...@@ -5,7 +6,19 @@ export default function Page(props) {
return <p>Loading...</p> return <p>Loading...</p>
} }
return <p id="props">{JSON.stringify(props)}</p> return (
<>
<p id="props">{JSON.stringify(props)}</p>
<Link href="/fallback-true-blog/first?hello=world" shallow>
<a id="to-query-shallow">to /fallback-true-blog/first?hello=world</a>
</Link>
<br />
<Link href="/fallback-true-blog/second" shallow>
<a id="to-no-query-shallow">to /fallback-true-blog/second</a>
</Link>
<br />
</>
)
} }
export function getStaticPaths() { export function getStaticPaths() {
......
...@@ -419,29 +419,12 @@ describe('Middleware Rewrite', () => { ...@@ -419,29 +419,12 @@ describe('Middleware Rewrite', () => {
}) })
it('should handle shallow navigation correctly (dynamic page)', async () => { it('should handle shallow navigation correctly (dynamic page)', async () => {
const browser = await webdriver(next.url, '/fallback-true-blog/first', { const browser = await webdriver(next.url, '/fallback-true-blog/first')
waitHydration: false,
})
let requests = []
browser.on('request', (req) => {
const url = req.url()
if (url.includes('_next/data')) requests.push(url)
})
// wait for initial query update request
await check(async () => { await check(async () => {
const didReq = await browser.eval('next.router.isReady') await browser.elementByCss('#to-query-shallow').click()
if (didReq || requests.length > 0) { return browser.eval('location.search')
requests = [] }, '?hello=world')
return 'yup'
}
}, 'yup')
await browser.eval(
`next.router.push('/fallback-true-blog/first?hello=world', undefined, { shallow: true })`
)
await check(() => browser.eval(`next.router.query.hello`), 'world')
expect(await browser.eval(`next.router.pathname`)).toBe( expect(await browser.eval(`next.router.pathname`)).toBe(
'/fallback-true-blog/[slug]' '/fallback-true-blog/[slug]'
...@@ -454,9 +437,7 @@ describe('Middleware Rewrite', () => { ...@@ -454,9 +437,7 @@ describe('Middleware Rewrite', () => {
) )
expect(await browser.eval('location.search')).toBe('?hello=world') expect(await browser.eval('location.search')).toBe('?hello=world')
await browser.eval( await browser.elementByCss('#to-no-query-shallow').click()
`next.router.push('/fallback-true-blog/second', undefined, { shallow: true })`
)
await check(() => browser.eval(`next.router.query.slug`), 'second') await check(() => browser.eval(`next.router.query.slug`), 'second')
expect(await browser.eval(`next.router.pathname`)).toBe( expect(await browser.eval(`next.router.pathname`)).toBe(
......
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