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 edge workers being re-used unexpectedly #41402

Merged
merged 7 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/next/server/next-server.ts
Expand Up @@ -1800,7 +1800,7 @@ export default class NextNodeServer extends BaseServer {
page: page,
body: getRequestMeta(params.request, '__NEXT_CLONABLE_BODY'),
},
useCache: !this.nextConfig.experimental.runtime,
useCache: false,
onWarning: params.onWarning,
})

Expand Down Expand Up @@ -2126,7 +2126,7 @@ export default class NextNodeServer extends BaseServer {
},
body: getRequestMeta(params.req, '__NEXT_CLONABLE_BODY'),
},
useCache: !this.nextConfig.experimental.runtime,
useCache: false,
onWarning: params.onWarning,
})

Expand Down
9 changes: 1 addition & 8 deletions packages/next/server/web/sandbox/context.ts
Expand Up @@ -314,15 +314,8 @@ interface ModuleContextOptions {
edgeFunctionEntry: Pick<EdgeFunctionDefinition, 'assets' | 'wasm'>
}

const pendingModuleCaches = new Map<string, Promise<ModuleContext>>()

function getModuleContextShared(options: ModuleContextOptions) {
let deferredModuleContext = pendingModuleCaches.get(options.moduleName)
if (!deferredModuleContext) {
deferredModuleContext = createModuleContext(options)
pendingModuleCaches.set(options.moduleName, deferredModuleContext)
}
return deferredModuleContext
return createModuleContext(options)
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/app-dir/app/app/slow-page-no-loading/page.js
@@ -0,0 +1,18 @@
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',
}
29 changes: 29 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -42,6 +42,35 @@ describe('app dir', () => {
})
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) {
it('should generate build traces correctly', async () => {
const trace = JSON.parse(
Expand Down