Skip to content

Commit

Permalink
feat: add support for edge app pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Oct 4, 2023
1 parent 79d6a15 commit 329a9ae
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/next-swc/crates/next-core/src/next_app/app_page_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ pub async fn get_app_page_entry(
let file = File::from(result.build());
let source = VirtualSource::new(source.ident().path(), AssetContent::file(file.into()));

let rsc_entry = context.process(
let mut rsc_entry = context.process(
Vc::upcast(source),
Value::new(ReferenceType::Internal(Vc::cell(inner_assets))),
);

if is_edge {
todo!("edge pages are not supported yet")
}
rsc_entry = wrap_edge_entry(context, project_root, rsc_entry).await?;
};

let Some(rsc_entry) =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkPlaceable>>(rsc_entry).await?
Expand All @@ -125,3 +125,30 @@ pub async fn get_app_page_entry(
}
.cell())
}

async fn wrap_edge_entry(
context: Vc<ModuleAssetContext>,
project_root: Vc<FileSystemPath>,
entry: Vc<Box<dyn Module>>,
) -> Result<Vc<Box<dyn Module>>> {
const INNER: &str = "INNER_RSC_ENTRY";

let source = load_next_js_template(
"edge-app-route.js",
project_root,
indexmap! {
"VAR_USERLAND" => INNER.to_string(),
},
indexmap! {},
)
.await?;

let inner_assets = indexmap! {
INNER.to_string() => entry
};

Ok(context.process(
Vc::upcast(source),
Value::new(ReferenceType::Internal(Vc::cell(inner_assets))),
))
}

0 comments on commit 329a9ae

Please sign in to comment.