Commit 42fa76a3 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix app dir with latest next.js (vercel/turbo#4134)

### Description

* [fix manifest for
__ssr_module_mapping__](https://github.com/vercel/turbo/commit/4abd87312d05a74ee858a8f556bfe567f3a9e008)
* [add missing styled-jsx
alias](https://github.com/vercel/turbo/commit/d9b4a4df7f81b18e657689f4e182bc9ef2259633)

### Testing Instructions

layout-playground
parent 2ffcc59e
......@@ -137,26 +137,51 @@ async function runOperation(renderData: RenderData) {
tree = [info.segment, { children: tree }, components];
}
const proxyMethodsForModule = (
id: string
): ProxyHandler<FlightManifest["__ssr_module_mapping__"][""]> => ({
get(_target, name) {
return {
id,
chunks: JSON.parse(id)[1],
name,
};
},
});
const proxyMethodsNested = (): ProxyHandler<
FlightManifest["__ssr_module_mapping__"]
> => {
return {
get(target, name, receiver) {
if (name === "__ssr_module_mapping__") {
return manifest;
}
if (name === "__entry_css_files__") {
return __entry_css_files__;
}
return new Proxy({}, proxyMethodsForModule(name as string));
},
};
};
const proxyMethods = (): ProxyHandler<FlightManifest> => {
return {
get(_target, key: string) {
if (key === "__ssr_module_mapping__") {
return manifest;
return new Proxy({} as any, proxyMethodsNested());
}
if (key === "__entry_css_files__") {
return __entry_css_files__;
}
// The key is a `${file}#${name}`, but `file` can contain `#` itself.
// There are 3 possibilities:
// "file" => id = "file", name = "*"
// There are 2 possibilities:
// "file#" => id = "file", name = ""
// "file#foo" => id = "file", name = "foo"
const pos = key.lastIndexOf("#");
let id = key;
let name = "";
if (pos === -1) {
name = "*";
throw new Error("key need to be in format of ${file}#${name}");
} else {
id = key.slice(0, pos);
name = key.slice(pos + 1);
......
......@@ -396,6 +396,7 @@ pub async fn insert_next_shared_aliases(
);
import_map.insert_singleton_alias("@swc/helpers", get_next_package(project_path));
import_map.insert_singleton_alias("styled-jsx", get_next_package(project_path));
import_map.insert_singleton_alias("next", project_path);
import_map.insert_singleton_alias("react", project_path);
import_map.insert_singleton_alias("react-dom", project_path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment