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
b457ed82
Commit
b457ed82
authored
Jul 15, 2025
by
Luke Sandberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some handling of components with no refs
parent
5ac3094b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
37 deletions
+30
-37
client_references.rs
crates/next-api/src/client_references.rs
+30
-37
No files found.
crates/next-api/src/client_references.rs
View file @
b457ed82
...
@@ -208,47 +208,40 @@ pub async fn map_client_references(
...
@@ -208,47 +208,40 @@ pub async fn map_client_references(
let
mut
memo
=
FxHashMap
::
default
();
let
mut
memo
=
FxHashMap
::
default
();
let
mut
client_references_per_server_component
=
FxHashMap
::
default
();
let
mut
client_references_per_server_component
=
FxHashMap
::
default
();
for
(
module
,
client_reference_type
)
in
&
client_references
{
for
(
&
module
,
client_reference_type
)
in
&
client_references
{
let
ClientReferenceMapType
::
ServerComponent
(
_
)
=
client_reference_type
else
{
let
ClientReferenceMapType
::
ServerComponent
(
_
)
=
client_reference_type
else
{
continue
;
continue
;
};
};
dfs_collect_shallow_client_references
(
client_references_per_server_component
.insert
(
true
,
module
,
*
module
,
dfs_collect_shallow_client_references
(
graph
,
true
,
&
client_references
,
module
,
&
mut
memo
,
graph
,
&
mut
FxHashSet
::
default
(),
&
client_references
,
)
&
mut
memo
,
.expect
(
"entry points cannot be in the middle of a cycle"
);
&
mut
FxHashSet
::
default
(),
}
),
// Drop everything from the map except server components, this frees memory and decrements
);
// ref counts so we can avoid copies later.
memo
.retain
(|
k
,
_
|
{
matches!
(
client_references
.get
(
k
),
Some
(
ClientReferenceMapType
::
ServerComponent
(
_
))
)
});
for
(
module
,
client_reference_type
)
in
&
client_references
{
let
ClientReferenceMapType
::
ServerComponent
(
_
)
=
client_reference_type
else
{
continue
;
};
let
refs
=
memo
.remove
(
module
)
.expect
(
"everything should have been computed above"
);
if
let
Some
(
refs
)
=
refs
{
// In the most common case each server component should be the only thing retaining
// the Rc, if not, then at least the next one will get to avoid the
// copy.
let
refs
:
Box
<
[
_
]
>
=
match
Rc
::
try_unwrap
(
refs
)
{
Ok
(
owned
)
=>
owned
.into_boxed_slice
(),
Err
(
shared
)
=>
shared
.to_vec
()
.into_boxed_slice
(),
};
client_references_per_server_component
.insert
(
*
module
,
refs
);
}
}
}
debug_assert!
(
memo
.is_empty
());
// Drop everything from the map except server components, this frees memory and, critically,
// decrements ref counts so we can avoid copies below.
drop
(
memo
);
let
client_references_per_server_component
=
client_references_per_server_component
.into_iter
()
.filter_map
(|(
k
,
v
)|
match
v
{
None
=>
None
,
Some
(
refs
)
=>
{
// Avoid a copy in the common cas
let
refs
:
Box
<
[
_
]
>
=
match
Rc
::
try_unwrap
(
refs
)
{
Ok
(
owned
)
=>
owned
.into_boxed_slice
(),
Err
(
shared
)
=>
shared
.to_vec
()
.into_boxed_slice
(),
};
Some
((
k
,
refs
))
}
})
.collect
();
Ok
(
ClientReferencesSet
::
new
(
ClientReferencesSet
{
Ok
(
ClientReferencesSet
::
new
(
ClientReferencesSet
{
client_references
,
client_references
,
...
...
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