Skip to content

Commit

Permalink
fix fallback overlay (vercel#2829)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony authored Nov 25, 2022
1 parent beebae2 commit e045476
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.rs]
indent_size = 4

[*.t]
trim_trailing_whitespace = false

Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/app_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub async fn create_app_source(
let server_runtime_entries =
vec![ProcessEnvAssetVc::new(project_root, env).as_ecmascript_chunk_placeable()];

let fallback_page = get_fallback_page(project_root, server_root, browserslist_query);
let fallback_page = get_fallback_page(project_root, server_root, env, browserslist_query);

Ok(create_app_source_for_directory(
context_ssr,
Expand Down
11 changes: 8 additions & 3 deletions crates/next-core/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;

use anyhow::{bail, Result};
use turbo_tasks::Value;
use turbo_tasks_env::ProcessEnvVc;
use turbo_tasks_fs::FileSystemPathVc;
use turbopack::{
ecmascript::EcmascriptModuleAssetVc, transition::TransitionsByNameVc, ModuleAssetContextVc,
Expand All @@ -17,7 +18,7 @@ use crate::{
embed_js::attached_next_js_package_path,
next_client::context::{
get_client_chunking_context, get_client_environment, get_client_module_options_context,
get_client_resolve_options_context, ContextType,
get_client_resolve_options_context, get_client_runtime_entries, ContextType,
},
next_import_map::insert_next_shared_aliases,
runtime::resolve_runtime_request,
Expand All @@ -27,13 +28,15 @@ use crate::{
pub async fn get_fallback_page(
project_root: FileSystemPathVc,
dev_server_root: FileSystemPathVc,
env: ProcessEnvVc,
browserslist_query: &str,
) -> Result<DevHtmlAssetVc> {
let ty = Value::new(ContextType::Other);
let ty = Value::new(ContextType::Fallback);
let environment = get_client_environment(browserslist_query);
let resolve_options_context = get_client_resolve_options_context(project_root, ty);
let module_options_context = get_client_module_options_context(project_root, environment, ty);
let chunking_context = get_client_chunking_context(project_root, dev_server_root, ty);
let entries = get_client_runtime_entries(project_root, env, ty);

let mut import_map = ImportMap::empty();
insert_next_shared_aliases(&mut import_map, attached_next_js_package_path(project_root));
Expand All @@ -46,6 +49,8 @@ pub async fn get_fallback_page(
)
.into();

let runtime_entries = entries.resolve_entries(context);

let fallback_chunk = resolve_runtime_request(
PlainResolveOriginVc::new(context, project_root).into(),
"entry/fallback",
Expand All @@ -59,7 +64,7 @@ pub async fn get_fallback_page(
bail!("fallback runtime entry is not an ecmascript module");
};

let chunk = module.as_evaluated_chunk(chunking_context, None);
let chunk = module.as_evaluated_chunk(chunking_context, Some(runtime_entries));

Ok(DevHtmlAssetVc::new(
dev_server_root.join("fallback.html"),
Expand Down
5 changes: 3 additions & 2 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn get_client_environment(browserslist_query: &str) -> EnvironmentVc {
pub enum ContextType {
Pages { pages_dir: FileSystemPathVc },
App { app_dir: FileSystemPathVc },
Fallback,
Other,
}

Expand Down Expand Up @@ -167,7 +168,7 @@ pub fn get_client_chunking_context(
ContextType::Pages { .. } | ContextType::App { .. } => {
server_root.join("/_next/static/chunks")
}
ContextType::Other => server_root.join("/_chunks"),
ContextType::Fallback | ContextType::Other => server_root.join("/_chunks"),
},
get_client_assets_path(server_root, ty),
)
Expand All @@ -184,7 +185,7 @@ pub fn get_client_assets_path(
ContextType::Pages { .. } | ContextType::App { .. } => {
server_root.join("/_next/static/assets")
}
ContextType::Other => server_root.join("/_assets"),
ContextType::Fallback | ContextType::Other => server_root.join("/_assets"),
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn get_next_client_import_map(
request_to_import_mapping(app_dir, "next/dist/compiled/react-dom/*"),
);
}
ContextType::Fallback => {}
ContextType::Other => {}
}
import_map.cell()
Expand Down Expand Up @@ -86,6 +87,7 @@ pub fn get_next_client_fallback_import_map(ty: Value<ContextType>) -> ImportMapV
);
}
}
ContextType::Fallback => {}
ContextType::Other => {}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/server_rendered_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn create_server_rendered_source(
let server_runtime_entries =
vec![ProcessEnvAssetVc::new(project_path, env).as_ecmascript_chunk_placeable()];

let fallback_page = get_fallback_page(project_path, server_root, browserslist_query);
let fallback_page = get_fallback_page(project_path, server_root, env, browserslist_query);

let server_rendered_source = create_server_rendered_source_for_directory(
project_path,
Expand Down

0 comments on commit e045476

Please sign in to comment.