Skip to content

Commit

Permalink
add support for assets in edge (#63209)
Browse files Browse the repository at this point in the history
### What?

add support for `new URL(..., import.meta.url)` assets in edge. e. g.
needed for og-image.

### Why?

### Turbopack Changes

* vercel/turborepo#7712 <!-- Tobias Koppers - allow
to use full urls in browser runtime -->

Closes PACK-2725
  • Loading branch information
sokra authored Mar 12, 2024
1 parent 11af8dd commit 18547d5
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 77 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ swc_core = { version = "0.90.17", features = [
testing = { version = "0.35.20" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.4" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.5" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.5" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240312.5" }

# General Deps

Expand Down
17 changes: 12 additions & 5 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,19 @@ impl AppEndpoint {
async fn output(self: Vc<Self>) -> Result<Vc<AppEndpointOutput>> {
let this = self.await?;

let (app_entry, process_client, process_ssr) = match this.ty {
let (app_entry, process_client, process_ssr, has_client_side_assets) = match this.ty {
AppEndpointType::Page { ty, loader_tree } => (
self.app_page_entry(loader_tree),
true,
matches!(ty, AppPageEndpointType::Html),
true,
),
// NOTE(alexkirsz) For routes, technically, a lot of the following code is not needed,
// as we know we won't have any client references. However, for now, for simplicity's
// sake, we just do the same thing as for pages.
AppEndpointType::Route { path } => (self.app_route_entry(path), false, false),
AppEndpointType::Route { path } => (self.app_route_entry(path), false, false, false),
AppEndpointType::Metadata { metadata } => {
(self.app_metadata_entry(metadata), false, false)
(self.app_metadata_entry(metadata), false, false, false)
}
};

Expand Down Expand Up @@ -613,7 +614,10 @@ impl AppEndpoint {
NextRuntime::NodeJs => {
Vc::upcast(this.app_project.project().server_chunking_context())
}
NextRuntime::Edge => this.app_project.project().edge_chunking_context(),
NextRuntime::Edge => this
.app_project
.project()
.edge_chunking_context(has_client_side_assets),
})
} else {
None
Expand Down Expand Up @@ -837,7 +841,10 @@ impl AppEndpoint {
let endpoint_output = match runtime {
NextRuntime::Edge => {
// create edge chunks
let chunking_context = this.app_project.project().edge_chunking_context();
let chunking_context = this
.app_project
.project()
.edge_chunking_context(has_client_side_assets);
let mut evaluatable_assets = this
.app_project
.edge_rsc_runtime_entries()
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl InstrumentationEndpoint {
};
evaluatable_assets.push(evaluatable);

let edge_chunking_context = self.project.edge_chunking_context();
let edge_chunking_context = self.project.edge_chunking_context(false);

let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
module.ident(),
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl MiddlewareEndpoint {
.context("Entry module must be evaluatable")?;
evaluatable_assets.push(evaluatable);

let edge_chunking_context = self.project.edge_chunking_context();
let edge_chunking_context = self.project.edge_chunking_context(true);

let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
module.ident(),
Expand Down
Loading

0 comments on commit 18547d5

Please sign in to comment.