-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
add edge rendering for app dir for Turbopack #50830
Merged
Merged
Changes from 58 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
03886a8
deduplicate part of the next-app-loader
sokra 944c3aa
parse segment config from loader tree
sokra 4e0176d
extra manifest and next_require code into separate file
sokra c094ea3
fixup
sokra 87b629d
fixup
sokra cc1cae2
prettier
sokra 1a0d55d
pull out common code into separate files
sokra 57309fd
WIP
sokra ae92832
WIP
sokra e3bbb6c
WIP
sokra 7d0ccaf
WIP
sokra d569b0b
WIP: working
sokra 3218b5a
fix types
sokra 3647a48
allow to enable source maps for node.js debugging
sokra 299ab1f
types fixes
sokra f425b82
always start on port 3000 with TURBOPACK_DEBUG_START
sokra e064377
fix open call
sokra 2855a6c
add TURBOPACK_DEBUG_OPEN
sokra 6a9a913
fix layer
sokra 2931e79
remove console.log
sokra 90e081e
update test case
sokra addf581
improve test result reporting, remove cleanup
sokra cb765b8
fmt
sokra 8cb01cd
prettier
sokra 2d18e8c
remove debug script
sokra 82dca72
use ESM reexports
sokra afffe05
fix types
sokra f736099
clippy
sokra e710ce1
warnings
sokra d72b179
fix enhanceGlobals
sokra 27143a1
use cjs version
sokra 40419ba
remove disk paths
sokra 09b930e
entry-base need to be ESM
sokra acf76b1
improve error message
sokra cdbcc27
avoid double declare globals
sokra 7bf5531
magic hacks by wyattjoh
sokra 0f10b0d
add buildId
sokra 804e6ab
updates for rebase
sokra 64095fd
no need to use esm version
sokra f19cf28
fix incorrect import
sokra 9d8310a
prettier
sokra ae8ce04
Merge branch 'canary' into sokra/app-edge
sokra 331428f
Merge branch 'canary' into sokra/app-edge
sokra f442982
move update response logic into separate function
sokra 9f245e3
review
sokra 687aa6f
referred_region -> preferred_region
sokra 54aaeb5
use destructuring
sokra bc1a5b8
rename sibling -> parallel
sokra 8ffb4bf
remove NODE_JS_SOURCE_MAPS const in favor of env var
sokra 68adc09
add comment
sokra bc621b6
dedupe alias
sokra 291d6f6
cleanup after test case
sokra b3f8a41
Revert "dedupe alias"
sokra 114199c
expose `__next_app__` with require and loadChunk combined
sokra fd9814c
add comments
sokra c6fe47f
improve url parsing
sokra bd2800b
link issue
sokra 3334d1c
Merge remote-tracking branch 'origin/canary' into sokra/app-edge
sokra e1ee57b
fix typo
sokra 249265c
Merge branch 'canary' into sokra/app-edge
sokra 8dedf4d
use destructuring
sokra a739e5b
link issue
sokra 1af0d49
Merge branch 'canary' into sokra/app-edge
sokra d615de4
Merge branch 'canary' into sokra/app-edge
sokra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
packages/next-swc/crates/next-core/js/src/entry/app-edge-renderer.tsx
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,82 @@ | ||
// IPC need to be the first import to allow it to catch errors happening during | ||
// the other imports | ||
import startOperationStreamHandler from '../internal/operation-stream' | ||
|
||
import { join } from 'path' | ||
import { parse as parseUrl } from 'node:url' | ||
|
||
import { runEdgeFunction } from '../internal/edge' | ||
import { headersFromEntries, initProxiedHeaders } from '../internal/headers' | ||
import { NodeNextRequest } from 'next/dist/server/base-http/node' | ||
|
||
import type { IncomingMessage } from 'node:http' | ||
import type { RenderData } from 'types/turbopack' | ||
|
||
import chunkGroup from 'INNER_EDGE_CHUNK_GROUP' | ||
import { attachRequestMeta } from '../internal/next-request-helpers' | ||
import { Readable } from 'stream' | ||
|
||
startOperationStreamHandler(async (renderData: RenderData, respond) => { | ||
const { response } = await runOperation(renderData) | ||
|
||
if (response == null) { | ||
throw new Error('no html returned') | ||
} | ||
|
||
const channel = respond({ | ||
status: response.status, | ||
// @ts-expect-error Headers is iterable since node.js 18 | ||
headers: [...response.headers], | ||
}) | ||
|
||
if (response.body) { | ||
const reader = response.body.getReader() | ||
for (;;) { | ||
let { done, value } = await reader.read() | ||
if (done) { | ||
break | ||
} | ||
channel.chunk(Buffer.from(value!)) | ||
} | ||
} | ||
|
||
channel.end() | ||
}) | ||
|
||
async function runOperation(renderData: RenderData) { | ||
const edgeInfo = { | ||
name: 'edge', | ||
paths: chunkGroup.map((chunk: string) => | ||
join(process.cwd(), '.next/server/app', chunk) | ||
), | ||
wasm: [], | ||
env: Object.keys(process.env), | ||
assets: [], | ||
} | ||
|
||
const parsedUrl = parseUrl(renderData.originalUrl, true) | ||
const incoming = new Readable() as IncomingMessage | ||
incoming.push(null) | ||
incoming.url = renderData.originalUrl | ||
incoming.method = renderData.method | ||
incoming.headers = initProxiedHeaders( | ||
headersFromEntries(renderData.rawHeaders), | ||
renderData.data?.serverInfo | ||
) | ||
const req = new NodeNextRequest(incoming) | ||
attachRequestMeta(req, parsedUrl, req.headers.host!) | ||
|
||
const res = await runEdgeFunction({ | ||
edgeInfo, | ||
outputDir: 'edge-pages', | ||
req, | ||
query: renderData.rawQuery, | ||
params: renderData.params, | ||
path: renderData.path, | ||
onWarning(warning) { | ||
console.warn(warning) | ||
}, | ||
}) | ||
|
||
return res as { response: Response } | ||
} |
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
1 change: 1 addition & 0 deletions
1
packages/next-swc/crates/next-core/js/src/entry/app/app-entry.tsx
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 @@ | ||
// This file is generated by app_source.rs |
Oops, something went wrong.
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.
How come these chunks aren't already under
.next/server/app
?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.
I think they relative to the immediate_output_directory, so this need to be added here.