Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
ccfe44d3
Commit
ccfe44d3
authored
Nov 05, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
7e638d8d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
162 additions
and
54 deletions
+162
-54
works.tsx
bench/basic-app/works.tsx
+0
-0
dynamic_imports.rs
crates/next-api/src/dynamic_imports.rs
+19
-2
module_graph.rs
crates/next-api/src/module_graph.rs
+21
-1
pages.rs
crates/next-api/src/pages.rs
+117
-46
page_entry.rs
crates/next-core/src/next_pages/page_entry.rs
+5
-5
No files found.
bench/basic-app/
pages/
works.tsx
→
bench/basic-app/works.tsx
View file @
ccfe44d3
File moved
crates/next-api/src/dynamic_imports.rs
View file @
ccfe44d3
...
...
@@ -26,8 +26,8 @@ use next_core::{
};
use
serde
::{
Deserialize
,
Serialize
};
use
turbo_tasks
::{
FxIndexMap
,
NonLocalValue
,
ReadRef
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
Vc
,
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
FxIndexMap
,
NonLocalValue
,
ReadRef
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
ValueDefault
,
Vc
,
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
};
use
turbopack_core
::{
chunk
::{
...
...
@@ -107,6 +107,23 @@ pub struct DynamicImportedChunks(
>
,
);
#[turbo_tasks
::
value_impl]
impl
DynamicImportedChunks
{
#[turbo_tasks
::
function]
pub
async
fn
concatenate
(
&
self
,
other
:
Vc
<
Self
>
)
->
Result
<
Vc
<
Self
>>
{
let
mut
chunks
=
self
.
0
.clone
();
chunks
.extend
(
other
.await
?
.iter
()
.map
(|(
k
,
v
)|
(
*
k
,
*
v
)));
Ok
(
Vc
::
cell
(
chunks
))
}
}
#[turbo_tasks
::
value_impl]
impl
ValueDefault
for
DynamicImportedChunks
{
#[turbo_tasks
::
function]
fn
value_default
()
->
Vc
<
Self
>
{
Self
::
default
()
.cell
()
}
}
#[derive(
Clone,
PartialEq,
Eq,
ValueDebugFormat,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
)]
...
...
crates/next-api/src/module_graph.rs
View file @
ccfe44d3
...
...
@@ -16,7 +16,8 @@ use rustc_hash::FxHashMap;
use
tracing
::
Instrument
;
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
CollectiblesSource
,
FxIndexMap
,
FxIndexSet
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
Vc
,
CollectiblesSource
,
FxIndexMap
,
FxIndexSet
,
ResolvedVc
,
TryFlatJoinIterExt
,
TryJoinIterExt
,
ValueToString
,
Vc
,
};
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbopack
::
css
::{
CssModuleAsset
,
ModuleCssAsset
};
...
...
@@ -75,6 +76,25 @@ impl NextDynamicGraph {
async
move
{
let
data
=
&*
self
.data.await
?
;
let
graph
=
&*
self
.graph.await
?
;
// println!(
// "get {:?} {} {:#?} {:#?} {:#?}",
// entry,
// entry.ident().to_string().await?,
// data.keys()
// .map(|m| m.ident().to_string())
// .try_join()
// .await?,
// graph
// .entry_modules()
// .map(|m| m.ident().to_string())
// .try_join()
// .await?,
// graph
// .enumerate_nodes()
// .map(|n| n.1.module().ident().to_string())
// .try_join()
// .await?
// );
#[derive(Clone,
PartialEq,
Eq)]
enum
VisitState
{
...
...
crates/next-api/src/pages.rs
View file @
ccfe44d3
...
...
@@ -30,8 +30,8 @@ use serde::{Deserialize, Serialize};
use
tracing
::
Instrument
;
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
Completion
,
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TaskInput
,
ValueToString
,
Vc
,
fxindexmap
,
fxindexset
,
trace
::
TraceRawVcs
,
Completion
,
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TaskInput
,
TryJoinIterExt
,
ValueDefault
,
ValueToString
,
Vc
,
fxindexmap
,
fxindexset
,
trace
::
TraceRawVcs
,
};
use
turbo_tasks_fs
::{
self
,
File
,
FileContent
,
FileSystem
,
FileSystemPath
,
FileSystemPathOption
,
VirtualFileSystem
,
...
...
@@ -51,7 +51,7 @@ use turbopack_core::{
context
::
AssetContext
,
file_source
::
FileSource
,
ident
::{
AssetIdent
,
Layer
},
module
::
Module
,
module
::
{
Module
,
OptionModule
}
,
module_graph
::{
GraphEntries
,
ModuleGraph
,
SingleModuleGraph
,
VisitedModules
,
chunk_group_info
::{
ChunkGroup
,
ChunkGroupEntry
},
...
...
@@ -663,6 +663,40 @@ impl PageEndpoint {
)))
}
#[turbo_tasks
::
function]
async
fn
app_client_module
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
OptionModule
>>
{
let
this
=
self
.await
?
;
if
this
.pathname
==
"/_app"
||
this
.pathname
==
"/_document"
{
Ok
(
Vc
::
cell
(
None
))
}
else
{
let
item
=
this
.pages_structure.await
?
.app
;
let
source
=
Vc
::
upcast
(
FileSource
::
new
(
item
.file_path
()
.owned
()
.await
?
));
let
page_loader
=
create_page_loader_entry_module
(
Vc
::
upcast
(
this
.pages_project
.client_module_context
()),
source
,
rcstr!
(
"/_app"
),
)
.to_resolved
()
.await
?
;
if
matches!
(
*
this
.pages_project
.project
()
.next_mode
()
.await
?
,
NextMode
::
Development
)
&&
let
Some
(
chunkable
)
=
ResolvedVc
::
try_downcast
(
page_loader
)
{
return
Ok
(
Vc
::
cell
(
Some
(
ResolvedVc
::
upcast
(
HmrEntryModule
::
new
(
AssetIdent
::
from_path
(
item
.await
?
.base_path
.clone
()),
*
chunkable
,
)
.to_resolved
()
.await
?
,
))));
}
Ok
(
Vc
::
cell
(
Some
(
page_loader
)))
}
}
#[turbo_tasks
::
function]
async
fn
client_module
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
Box
<
dyn
Module
>>>
{
let
this
=
self
.await
?
;
...
...
@@ -715,7 +749,12 @@ impl PageEndpoint {
async
fn
client_module_graph
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
ModuleGraph
>>
{
let
this
=
self
.await
?
;
let
project
=
this
.pages_project
.project
();
let
evaluatable_assets
=
self
.client_evaluatable_assets
();
let
mut
evaluatable_assets
=
self
.client_evaluatable_assets
();
if
let
Some
(
module
)
=
&*
self
.app_client_module
()
.await
?
{
let
evaluatable_module
=
ResolvedVc
::
try_sidecast
::
<
Box
<
dyn
EvaluatableAsset
>>
(
*
module
)
.context
(
"expected an evaluateable asset"
)
?
;
evaluatable_assets
=
evaluatable_assets
.with_entry
(
*
evaluatable_module
);
}
Ok
(
project
.module_graph_for_modules
(
evaluatable_assets
))
}
...
...
@@ -732,8 +771,8 @@ impl PageEndpoint {
let
mut
graphs
=
vec!
[];
let
mut
visited_modules
=
VisitedModules
::
empty
();
for
module
in
[
ssr_chunk_module
.document_module
,
ssr_chunk_module
.app_module
,
ssr_chunk_module
.document_
ssr_
module
,
ssr_chunk_module
.app_
ssr_
module
,
]
.into_iter
()
.flatten
()
...
...
@@ -858,8 +897,8 @@ impl PageEndpoint {
.module
();
InternalSsrChunkModule
{
ssr_module
:
ssr_module
.to_resolved
()
.await
?
,
app_module
:
None
,
document_module
:
None
,
app_
ssr_
module
:
None
,
document_
ssr_
module
:
None
,
// /_app and /_document are always rendered for Node.js for this case. For edge
// they're included in the page bundle.
runtime
:
NextRuntime
::
NodeJs
,
...
...
@@ -881,8 +920,8 @@ impl PageEndpoint {
InternalSsrChunkModule
{
ssr_module
:
modules
.ssr_module
,
app_
module
:
modules
.app
_module
,
document_
module
:
modules
.document
_module
,
app_
ssr_module
:
modules
.app_ssr
_module
,
document_
ssr_module
:
modules
.document_ssr
_module
,
runtime
,
regions
:
config
.preferred_region
.clone
(),
}
...
...
@@ -901,8 +940,8 @@ impl PageEndpoint {
.await
?
;
InternalSsrChunkModule
{
ssr_module
:
modules
.ssr_module
,
app_
module
:
modules
.app
_module
,
document_
module
:
modules
.document
_module
,
app_
ssr_module
:
modules
.app_ssr
_module
,
document_
ssr_module
:
modules
.document_ssr
_module
,
runtime
,
regions
:
config
.preferred_region
.clone
(),
}
...
...
@@ -925,8 +964,8 @@ impl PageEndpoint {
let
InternalSsrChunkModule
{
ssr_module
,
app_module
,
document_module
,
app_
ssr_
module
,
document_
ssr_
module
,
runtime
,
ref
regions
,
}
=
*
self
.internal_ssr_chunk_module
()
.await
?
;
...
...
@@ -937,7 +976,7 @@ impl PageEndpoint {
// moment, which only needs the client graph anyway.
let
ssr_module_graph
=
self
.ssr_module_graph
();
let
next_dynamic_import
s
=
if
let
PageEndpointType
::
Html
=
this
.ty
{
let
dynamic_import_entrie
s
=
if
let
PageEndpointType
::
Html
=
this
.ty
{
let
client_availability_info
=
self
.client_chunk_group
()
.await
?
.availability_info
;
let
client_module_graph
=
self
.client_module_graph
();
...
...
@@ -950,12 +989,12 @@ impl PageEndpoint {
// We only validate the global css imports when there is not a `app` folder at the
// root of the project.
if
project
.app_project
()
.await
?
.is_none
()
{
// We recreate the app_module here because the one provided from the
// We recreate the app_
ssr_
module here because the one provided from the
// `internal_ssr_chunk_module` is not the same as the one
// provided from the `client_module_graph`. There can be cases where
// the `app_module` is None, and we are processing the `pages/_app.js` file
// the `app_
ssr_
module` is None, and we are processing the `pages/_app.js` file
// as a page rather than the app module.
let
app_module
=
project
let
app_
ssr_
module
=
project
.pages_project
()
.client_module_context
()
.process
(
...
...
@@ -969,33 +1008,61 @@ impl PageEndpoint {
.module
();
global_information
.validate_pages_css_imports
(
self
.client_module
(),
app_module
)
.validate_pages_css_imports
(
self
.client_module
(),
app_
ssr_
module
)
.await
?
;
}
let
next_dynamic_imports
=
global_information
.get_next_dynamic_imports_for_endpoint
(
self
.client_module
())
.await
?
;
Some
((
next_dynamic_imports
,
client_availability_info
))
}
else
{
None
};
let
dynamic_import_entries
=
if
let
Some
((
next_dynamic_imports
,
client_availability_info
,
))
=
next_dynamic_imports
{
collect_next_dynamic_chunks
(
self
.client_module_graph
(),
project
.client_chunking_context
(),
next_dynamic_imports
,
NextDynamicChunkAvailability
::
AvailabilityInfo
(
client_availability_info
),
)
.await
?
// if this.pathname == "/" {
// println!(
// "{} {:#?}",
// this.pathname,
// client_module_graph.read_graphs().await?.get_ids().await?
// );
// }
// next/dynamic imports are written into a per-page manifest, which also needs to
// list the imports in _app.
let
mut
chunks
=
DynamicImportedChunks
::
value_default
();
for
module
in
[
self
.app_client_module
()
.await
?
.map
(|
m
|
*
m
),
Some
(
self
.client_module
()),
]
.into_iter
()
.flatten
()
{
let
next_dynamic_imports
=
global_information
.get_next_dynamic_imports_for_endpoint
(
module
)
.await
?
;
// if this.pathname == "/" || this.pathname == "/_app" {
// println!(
// "next_dynamic_imports: {:?} {:?} {:?} {:?}",
// this.pathname,
// module,
// module.ident().to_string().await?,
// next_dynamic_imports
// .iter()
// .map(|m| m.0.ident().to_string())
// .try_join()
// .await?
// );
// }
chunks
=
chunks
.concatenate
(
*
collect_next_dynamic_chunks
(
self
.client_module_graph
(),
project
.client_chunking_context
(),
next_dynamic_imports
,
NextDynamicChunkAvailability
::
AvailabilityInfo
(
client_availability_info
,
),
)
.await
?
,
);
}
chunks
}
else
{
DynamicImportedChunks
::
default
()
.resolved_cell
()
};
DynamicImportedChunks
::
value_default
()
}
.to_resolved
()
.await
?
;
let
chunking_context
:
Vc
<
Box
<
dyn
ChunkingContext
>>
=
match
runtime
{
NextRuntime
::
NodeJs
=>
Vc
::
upcast
(
node_chunking_context
),
...
...
@@ -1005,7 +1072,11 @@ impl PageEndpoint {
let
mut
current_chunks
=
OutputAssets
::
empty
();
let
mut
current_referenced_assets
=
OutputAssets
::
empty
();
let
mut
current_availability_info
=
AvailabilityInfo
::
Root
;
for
layout
in
[
document_module
,
app_module
]
.iter
()
.flatten
()
.copied
()
{
for
layout
in
[
document_ssr_module
,
app_ssr_module
]
.iter
()
.flatten
()
.copied
()
{
let
span
=
tracing
::
trace_span!
(
"layout segment"
,
name
=
display
(
layout
.ident
()
.to_string
()
.await
?
)
...
...
@@ -1577,8 +1648,8 @@ impl PageEndpoint {
#[turbo_tasks
::
value]
pub
struct
InternalSsrChunkModule
{
pub
ssr_module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
pub
app_module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
document_module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
app_
ssr_
module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
document_
ssr_
module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
runtime
:
NextRuntime
,
pub
regions
:
Option
<
Vec
<
RcStr
>>
,
}
...
...
@@ -1701,8 +1772,8 @@ impl Endpoint for PageEndpoint {
let
ssr_chunk_module
=
self
.internal_ssr_chunk_module
()
.await
?
;
let
shared_entries
=
[
ssr_chunk_module
.document_module
,
ssr_chunk_module
.app_module
,
ssr_chunk_module
.document_
ssr_
module
,
ssr_chunk_module
.app_
ssr_
module
,
];
let
modules
=
shared_entries
...
...
crates/next-core/src/next_pages/page_entry.rs
View file @
ccfe44d3
...
...
@@ -25,8 +25,8 @@ use crate::{
#[turbo_tasks
::
value]
pub
struct
PageSsrEntryModule
{
pub
ssr_module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
pub
app_module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
document_module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
app_
ssr_
module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
pub
document_
ssr_
module
:
Option
<
ResolvedVc
<
Box
<
dyn
Module
>>>
,
}
#[turbo_tasks
::
function]
...
...
@@ -127,7 +127,7 @@ pub async fn create_page_ssr_entry_module(
let
pages_structure_ref
=
pages_structure
.await
?
;
let
(
app_
module
,
document
_module
)
=
if
is_page
{
let
(
app_
ssr_module
,
document_ssr
_module
)
=
if
is_page
{
// We process the document and app modules in the same context and reference type.
let
document_module
=
process_global_item
(
*
pages_structure_ref
.document
,
...
...
@@ -184,8 +184,8 @@ pub async fn create_page_ssr_entry_module(
Ok
(
PageSsrEntryModule
{
ssr_module
:
ssr_module
.to_resolved
()
.await
?
,
app_module
,
document_module
,
app_
ssr_
module
,
document_
ssr_
module
,
}
.cell
())
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment