Skip to content

Commit

Permalink
Merge branch 'canary' of github.com:Sam-Phillemon9493/next.js into up…
Browse files Browse the repository at this point in the history
…date-with-web-worker-example
  • Loading branch information
Sam-Phillemon9493 committed Sep 13, 2024
2 parents 646440a + e40574b commit 7a64044
Show file tree
Hide file tree
Showing 177 changed files with 21,431 additions and 17,788 deletions.
26 changes: 14 additions & 12 deletions .github/ISSUE_TEMPLATE/1.bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ body:
attributes:
label: Link to the code that reproduces this issue
description: |
A link to a **public** [GitHub repository](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) or a [CodeSandbox](https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template) minimal reproduction. Minimal reproductions should be created from our [bug report template with `npx create-next-app -e reproduction-template`](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) and should include only changes that contribute to the issue. To report a Pages Router related issue, you can use these templates: [`npx create-next-app -e reproduction-template-pages`](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages) or [CodeSandbox](https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template-pages)
A link to a **public** [GitHub repository](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) or a [CodeSandbox](https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template) minimal reproduction. Minimal reproductions should be created from our [bug report template with `npx create-next-app -e reproduction-template`](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) and should include only changes that contribute to the issue. To report a Pages Router related issue, you can use these templates: [`npx create-next-app -e reproduction-template-pages`](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages) or [CodeSandbox](https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template-pages).
If you decide to create your own minimal reproduction, please make sure test on canary. It is highly likely that the issue you are experiencing is already fixed in the canary version.
**Skipping this/providing an invalid link will result in the issue being closed.**
placeholder: 'https://github.com/user/my-minimal-nextjs-issue-reproduction'
Expand Down Expand Up @@ -55,18 +57,18 @@ body:
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.5.0
Version: Darwin Kernel Version 23.6.0
Binaries:
Node: 18.17.1
npm: 9.5.1
Yarn: 1.22.19
pnpm: N/A
Node: 20.17.0
npm: 10.8.2
Yarn: 1.22.22
pnpm: 9.10.0
Relevant Packages:
next: 13.4.20
eslint-config-next: 13.4.20
react: 18.2.0
react-dom: 18.2.0
typescript: 5.2.2
next: 15.0.0-canary.148
eslint-config-next: 15.0.0-canary.148
react: 19.0.0-rc-3dfd5d9e-20240910
react-dom: 19.0.0-rc-3dfd5d9e-20240910
typescript: 5.6.2
Next.js Config:
output: N/A
validations:
Expand Down Expand Up @@ -129,7 +131,7 @@ body:
description: |
Any extra information that might help us investigate. For example, where are you deploying your application (Vercel, Docker, other platform)? Is it only reproducible on that platform, or locally too? Is the issue only happening in a specific browser? etc.
placeholder: |
I tested my reproduction against different canary releases, and the first one that introduced the bug was "13.4.20-canary.13", since reverting to "13.4.20-canary.12" works.
I tested my reproduction against different canary releases, and the first one that introduced the bug was "15.0.0-canary.148", since reverting to "15.0.0-canary.147" works.
or
Expand Down
10 changes: 0 additions & 10 deletions Cargo.lock

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

39 changes: 39 additions & 0 deletions crates/next-api/src/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use anyhow::{bail, Result};
use turbo_tasks::{Completion, Vc};
use turbopack_core::module::Modules;

use crate::route::{Endpoint, WrittenEndpoint};

#[turbo_tasks::value]
pub struct EmptyEndpoint;

#[turbo_tasks::value_impl]
impl EmptyEndpoint {
#[turbo_tasks::function]
pub fn new() -> Vc<Self> {
EmptyEndpoint.cell()
}
}

#[turbo_tasks::value_impl]
impl Endpoint for EmptyEndpoint {
#[turbo_tasks::function]
fn write_to_disk(self: Vc<Self>) -> Result<Vc<WrittenEndpoint>> {
bail!("Empty endpoint can't be written to disk")
}

#[turbo_tasks::function]
fn server_changed(self: Vc<Self>) -> Vc<Completion> {
Completion::new()
}

#[turbo_tasks::function]
fn client_changed(self: Vc<Self>) -> Vc<Completion> {
Completion::new()
}

#[turbo_tasks::function]
fn root_modules(self: Vc<Self>) -> Vc<Modules> {
Vc::cell(vec![])
}
}
1 change: 1 addition & 0 deletions crates/next-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

mod app;
mod dynamic_imports;
mod empty;
pub mod entrypoints;
mod font;
pub mod global_module_id_strategy;
Expand Down
1 change: 0 additions & 1 deletion crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ impl PageEndpoint {
return Ok(Vc::upcast(HmrEntryModule::new(
AssetIdent::from_path(this.page.await?.base_path),
chunkable,
true,
)));
}
}
Expand Down
106 changes: 50 additions & 56 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use turbo_tasks::{
debug::ValueDebugFormat,
graph::{AdjacencyMap, GraphTraversal},
trace::TraceRawVcs,
Completion, Completions, IntoTraitRef, RcStr, ReadRef, State, TaskInput, TraitRef,
TransientInstance, TryFlatJoinIterExt, Value, Vc,
Completion, Completions, IntoTraitRef, RcStr, ReadRef, State, TaskInput, TransientInstance,
TryFlatJoinIterExt, Value, Vc,
};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem};
Expand All @@ -48,7 +48,6 @@ use turbopack_core::{
module::Modules,
output::{OutputAsset, OutputAssets},
resolve::{find_context_file, FindContextFileResult},
source::Source,
source_map::OptionSourceMap,
version::{Update, Version, VersionState, VersionedContent},
PROJECT_FILESYSTEM_NAME,
Expand All @@ -59,6 +58,7 @@ use turbopack_nodejs::NodeJsChunkingContext;
use crate::{
app::{AppProject, OptionAppProject, ECMASCRIPT_CLIENT_TRANSITION_NAME},
build,
empty::EmptyEndpoint,
entrypoints::Entrypoints,
global_module_id_strategy::GlobalModuleIdStrategyBuilder,
instrumentation::InstrumentationEndpoint,
Expand Down Expand Up @@ -860,57 +860,24 @@ impl Project {
}
}

let pages_document_endpoint = TraitRef::cell(
self.pages_project()
.document_endpoint()
.into_trait_ref()
.await?,
);
let pages_app_endpoint =
TraitRef::cell(self.pages_project().app_endpoint().into_trait_ref().await?);
let pages_error_endpoint = TraitRef::cell(
self.pages_project()
.error_endpoint()
.into_trait_ref()
.await?,
);
let pages_document_endpoint = self.pages_project().document_endpoint();
let pages_app_endpoint = self.pages_project().app_endpoint();
let pages_error_endpoint = self.pages_project().error_endpoint();

let middleware = find_context_file(
self.project_path(),
middleware_files(self.next_config().page_extensions()),
);
let middleware = if let FindContextFileResult::Found(fs_path, _) = *middleware.await? {
let source = Vc::upcast(FileSource::new(fs_path));
let middleware = self.find_middleware();
let middleware = if let FindContextFileResult::Found(..) = *middleware.await? {
Some(Middleware {
endpoint: TraitRef::cell(
Vc::upcast::<Box<dyn Endpoint>>(self.middleware_endpoint(source))
.into_trait_ref()
.await?,
),
endpoint: self.middleware_endpoint(),
})
} else {
None
};

let instrumentation = find_context_file(
self.project_path(),
instrumentation_files(self.next_config().page_extensions()),
);
let instrumentation = if let FindContextFileResult::Found(fs_path, _) =
*instrumentation.await?
{
let source = Vc::upcast(FileSource::new(fs_path));
let instrumentation = self.find_instrumentation();
let instrumentation = if let FindContextFileResult::Found(..) = *instrumentation.await? {
Some(Instrumentation {
node_js: TraitRef::cell(
Vc::upcast::<Box<dyn Endpoint>>(self.instrumentation_endpoint(source, false))
.into_trait_ref()
.await?,
),
edge: TraitRef::cell(
Vc::upcast::<Box<dyn Endpoint>>(self.instrumentation_endpoint(source, true))
.into_trait_ref()
.await?,
),
node_js: self.instrumentation_endpoint(false),
edge: self.instrumentation_endpoint(true),
})
} else {
None
Expand Down Expand Up @@ -978,24 +945,34 @@ impl Project {
}

#[turbo_tasks::function]
async fn middleware_endpoint(
self: Vc<Self>,
source: Vc<Box<dyn Source>>,
) -> Result<Vc<MiddlewareEndpoint>> {
fn find_middleware(self: Vc<Self>) -> Vc<FindContextFileResult> {
find_context_file(
self.project_path(),
middleware_files(self.next_config().page_extensions()),
)
}

#[turbo_tasks::function]
async fn middleware_endpoint(self: Vc<Self>) -> Result<Vc<Box<dyn Endpoint>>> {
let middleware = self.find_middleware();
let FindContextFileResult::Found(fs_path, _) = *middleware.await? else {
return Ok(Vc::upcast(EmptyEndpoint::new()));
};
let source = Vc::upcast(FileSource::new(fs_path));
let app_dir = *find_app_dir(self.project_path()).await?;
let ecmascript_client_reference_transition_name = (*self.app_project().await?)
.as_ref()
.map(|app_project| app_project.client_transition_name());

let middleware_asset_context = self.middleware_context();

Ok(MiddlewareEndpoint::new(
Ok(Vc::upcast(MiddlewareEndpoint::new(
self,
middleware_asset_context,
source,
app_dir,
ecmascript_client_reference_transition_name,
))
)))
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -1098,12 +1075,24 @@ impl Project {
)))
}

#[turbo_tasks::function]
fn find_instrumentation(self: Vc<Self>) -> Vc<FindContextFileResult> {
find_context_file(
self.project_path(),
instrumentation_files(self.next_config().page_extensions()),
)
}

#[turbo_tasks::function]
async fn instrumentation_endpoint(
self: Vc<Self>,
source: Vc<Box<dyn Source>>,
is_edge: bool,
) -> Result<Vc<InstrumentationEndpoint>> {
) -> Result<Vc<Box<dyn Endpoint>>> {
let instrumentation = self.find_instrumentation();
let FindContextFileResult::Found(fs_path, _) = *instrumentation.await? else {
return Ok(Vc::upcast(EmptyEndpoint::new()));
};
let source = Vc::upcast(FileSource::new(fs_path));
let app_dir = *find_app_dir(self.project_path()).await?;
let ecmascript_client_reference_transition_name = (*self.app_project().await?)
.as_ref()
Expand All @@ -1115,14 +1104,14 @@ impl Project {
self.node_instrumentation_context()
};

Ok(InstrumentationEndpoint::new(
Ok(Vc::upcast(InstrumentationEndpoint::new(
self,
instrumentation_asset_context,
source,
is_edge,
app_dir,
ecmascript_client_reference_transition_name,
))
)))
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -1328,3 +1317,8 @@ fn all_assets_from_entries_operation(
) -> Vc<OutputAssetsOperation> {
Vc::cell(all_assets_from_entries_operation_inner(operation))
}

#[turbo_tasks::function]
async fn stable_endpoint(endpoint: Vc<Box<dyn Endpoint>>) -> Result<Vc<Box<dyn Endpoint>>> {
Ok(endpoint)
}
32 changes: 25 additions & 7 deletions crates/next-api/src/versioned_content_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use anyhow::{bail, Result};
use indexmap::IndexSet;
use next_core::emit_assets;
use serde::{Deserialize, Serialize};
use turbo_tasks::{
Expand Down Expand Up @@ -31,11 +32,12 @@ struct MapEntry {
#[turbo_tasks::value(transparent)]
struct OptionMapEntry(Option<MapEntry>);

type PathToOutputOperation = HashMap<Vc<FileSystemPath>, Vc<OutputAssets>>;
type PathToOutputOperation = HashMap<Vc<FileSystemPath>, IndexSet<Vc<OutputAssets>>>;
type OutputOperationToComputeEntry = HashMap<Vc<OutputAssets>, Vc<OptionMapEntry>>;

#[turbo_tasks::value]
pub struct VersionedContentMap {
// TODO: turn into a bi-directional multimap, OutputAssets -> IndexSet<FileSystemPath>
map_path_to_op: State<PathToOutputOperation>,
map_op_to_compute_entry: State<OutputOperationToComputeEntry>,
}
Expand Down Expand Up @@ -110,15 +112,31 @@ impl VersionedContentMap {
Ok(entries)
}
let entries = get_entries(assets).await.unwrap_or_default();

self.await?.map_path_to_op.update_conditionally(|map| {
let mut changed = false;
for &(k, _) in entries.iter() {
if map.insert(k, assets) != Some(assets) {
changed = true;
}

// get current map's keys, subtract keys that don't exist in operation
let mut stale_assets = map.keys().copied().collect::<HashSet<_>>();

for (k, _) in entries.iter() {
let res = map.entry(*k).or_default().insert(assets);
stale_assets.remove(k);
changed = changed || res;
}

// Make more efficient with reverse map
for k in &stale_assets {
let res = map
.get_mut(k)
// guaranteed
.unwrap()
.remove(&assets);
changed = changed || res
}
changed
});

// Make sure all written client assets are up-to-date
let side_effects = emit_assets(assets, node_root, client_relative_path, client_output_path);
let map_entry = Vc::cell(Some(MapEntry {
Expand Down Expand Up @@ -201,7 +219,7 @@ impl VersionedContentMap {
async fn raw_get(&self, path: Vc<FileSystemPath>) -> Result<Vc<OptionMapEntry>> {
let assets = {
let map = self.map_path_to_op.get();
map.get(&path).copied()
map.get(&path).and_then(|m| m.iter().last().copied())
};
let Some(assets) = assets else {
return Ok(Vc::cell(None));
Expand Down
Loading

0 comments on commit 7a64044

Please sign in to comment.