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(switchable-runtime): Make it possible to switch between edge and server runtime in dev #39327
Merged
Merged
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
794f1b9
Move middlewareManifest from module scope, should be revalidated each…
de26faf
Invalidate server and edge when runtime has changed from one to the o…
a1fb10b
Tests for changing runtime
c6ecbed
Move entries deleting to on-demand-entry-handler
fc8b98d
Always emit files without comparing
65d5062
Unflakify tests
f7f9dd7
fix lint
5c0150b
Merge branch 'canary' into api-switch-runtime
7cdf254
the return returns
799b1df
Merge branch 'canary' of https://github.com/hanneslund/next.js into a…
ee1a849
Move deletion
bbad378
Add invalidate
87b680e
Merge branch 'canary' into api-switch-runtime
c745d94
Append the runtime to the filename in dev
29bf939
Merge branch 'canary' of https://github.com/hanneslund/next.js into a…
dc68db8
Remove invalidate call
896640d
Merge branch 'canary' of https://github.com/hanneslund/next.js into a…
a79a3b5
Clean up
081a873
Merge branch 'canary' into api-switch-runtime
54e7dc5
Merge branch 'canary' into api-switch-runtime
kodiakhq[bot] aab7d9d
Merge branch 'canary' into api-switch-runtime
ijjk 7616482
Merge branch 'canary' into api-switch-runtime
ijjk File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { createNext } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { check, renderViaHTTP } from 'next-test-utils' | ||
|
||
describe('edge-api-routes', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
'pages/index.js': ` | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} | ||
`, | ||
}, | ||
dependencies: {}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
test('Switch between runtimes - edge first', async () => { | ||
// Edge | ||
await next.patchFile( | ||
'pages/api/hello.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default () => new Response('edge response') | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello'), 'edge response') | ||
|
||
// Server | ||
await next.patchFile( | ||
'pages/api/hello.js', | ||
` | ||
export default function (req, res) { | ||
res.send('server response') | ||
} | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello'), 'server response') | ||
|
||
// Edge | ||
await next.patchFile( | ||
'pages/api/hello.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default () => new Response('edge response') | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello'), 'edge response') | ||
}) | ||
|
||
test('Switch between runtimes - server first', async () => { | ||
// Server | ||
await next.patchFile( | ||
'pages/api/hello2.js', | ||
` | ||
export default function (req, res) { | ||
res.send('server response') | ||
} | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello2'), 'server response') | ||
|
||
// Edge | ||
await next.patchFile( | ||
'pages/api/hello2.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default () => new Response('edge response') | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello2'), 'edge response') | ||
|
||
// Server | ||
await next.patchFile( | ||
'pages/api/hello2.js', | ||
` | ||
export default function (req, res) { | ||
res.send('server response') | ||
} | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello2'), 'server response') | ||
}) | ||
|
||
test('Recover from syntax error', async () => { | ||
await next.patchFile( | ||
'pages/api/hello3.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default () => new Response('edge response') | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello3'), 'edge response') | ||
|
||
// Syntax error | ||
await next.patchFile( | ||
'pages/api/hello3.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default => new Response('edge response') | ||
` | ||
) | ||
await check( | ||
() => renderViaHTTP(next.url, '/api/hello3'), | ||
/Unexpected token/ | ||
) | ||
|
||
// Fix syntax error | ||
await next.patchFile( | ||
'pages/api/hello3.js', | ||
` | ||
export const config = { | ||
runtime: 'experimental-edge', | ||
} | ||
|
||
export default () => new Response('edge response 2') | ||
` | ||
) | ||
await check(() => renderViaHTTP(next.url, '/api/hello3'), 'edge response 2') | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as any
because types didn't containoutput.compareBeforeEmit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sokra are there any performance drawbacks to doing this? Seems the comparison is failing in this case and it's not emitting the file when switched between compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly this won't be needed after this is fixed https://vercel.slack.com/archives/C035J346QQL/p1659704191110839