Skip to content

Commit

Permalink
Turbopack: Strip relative path prefix when generating PageLoaderAsset (
Browse files Browse the repository at this point in the history
…#54040)

### What?

Strip the relative path prefix (`_next/`) when generating the `PageLoaderAsset`. This is necessary because the page loader will internally use `__turbopack_load__`, which prepends the prefix back onto the path.

### Why?

Without this, we'd try loading `_next/_next/path/to/file.js`, because we'd prepend the prefix onto a path that already contains it.

### How?

When generating the page loader asset, we "proxy" the `OutputAsset` onto a path which has the prefix removed.

~~Depends on vercel/turbo#5717

Closes WEB-1377
  • Loading branch information
jridgewell committed Aug 17, 2023
1 parent 8def0c8 commit 11dfdf8
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 60 deletions.
74 changes: 37 additions & 37 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ swc_core = { version = "0.79.59" }
testing = { version = "0.33.21" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230814.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230816.1" }
# [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-230814.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230816.1" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230814.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230816.1" }

# General Deps

Expand Down Expand Up @@ -123,7 +123,9 @@ serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
serde_qs = "0.11.0"
serde_yaml = "0.9.17"
shadow-rs = { version = "0.23.0", default-features = false, features = ["tzdb"] }
shadow-rs = { version = "0.23.0", default-features = false, features = [
"tzdb",
] }
syn = "1.0.107"
tempfile = "3.3.0"
thiserror = "1.0.38"
Expand Down
8 changes: 7 additions & 1 deletion packages/next-swc/crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use next_core::{
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, Completion, TaskInput, TryJoinIterExt, Value, Vc};
use turbopack_binding::{
turbo::tasks_fs::{File, FileSystem, FileSystemPath, VirtualFileSystem},
turbo::tasks_fs::{File, FileSystem, FileSystemPath, FileSystemPathOption, VirtualFileSystem},
turbopack::{
build::BuildChunkingContext,
core::{
Expand Down Expand Up @@ -567,6 +567,7 @@ impl PageEndpoint {
Vc::upcast(client_chunking_context),
self.source(),
this.pathname,
self.client_relative_path(),
)));

Ok(Vc::cell(client_chunks))
Expand Down Expand Up @@ -811,6 +812,11 @@ impl PageEndpoint {

Ok(page_output.cell())
}

#[turbo_tasks::function]
fn client_relative_path(&self) -> Vc<FileSystemPathOption> {
Vc::cell(Some(self.pages_project.project().client_relative_path()))
}
}

#[turbo_tasks::value_impl]
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-core/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230814.2",
"@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230814.2",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230816.1",
"@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230816.1",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
Loading

0 comments on commit 11dfdf8

Please sign in to comment.