diff --git a/crates/next-custom-transforms/tests/errors.rs b/crates/next-custom-transforms/tests/errors.rs index aee4e1ce5614a7..ceddd98155994e 100644 --- a/crates/next-custom-transforms/tests/errors.rs +++ b/crates/next-custom-transforms/tests/errors.rs @@ -89,36 +89,12 @@ fn next_ssg_errors(input: PathBuf) { ); } -#[fixture("tests/errors/react-server-components/server-graph/**/input.js")] -fn react_server_components_server_graph_errors(input: PathBuf) { - use next_custom_transforms::transforms::react_server_components::{Config, Options}; - let output = input.parent().unwrap().join("output.js"); - test_fixture( - syntax(), - &|tr| { - server_components( - FileName::Real(PathBuf::from("/some-project/src/layout.js")).into(), - Config::WithOptions(Options { - is_react_server_layer: true, - dynamic_io_enabled: false, - }), - tr.comments.as_ref().clone(), - None, - ) - }, - &input, - &output, - FixtureTestConfig { - allow_error: true, - module: Some(true), - ..Default::default() - }, - ); -} - -#[fixture("tests/errors/react-server-components/client-graph/**/input.js")] -fn react_server_components_client_graph_errors(input: PathBuf) { +#[fixture("tests/errors/react-server-components/**/input.js")] +fn react_server_components_errors(input: PathBuf) { use next_custom_transforms::transforms::react_server_components::{Config, Options}; + let mut path_components = input.iter(); + let is_react_server_layer = path_components.any(|s| s.to_str() == Some("server-graph")); + let dynamic_io_enabled = path_components.any(|s| s.to_str() == Some("dynamic-io")); let output = input.parent().unwrap().join("output.js"); test_fixture( syntax(), @@ -126,8 +102,8 @@ fn react_server_components_client_graph_errors(input: PathBuf) { server_components( FileName::Real(PathBuf::from("/some-project/src/page.js")).into(), Config::WithOptions(Options { - is_react_server_layer: false, - dynamic_io_enabled: false, + is_react_server_layer, + dynamic_io_enabled, }), tr.comments.as_ref().clone(), None, diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/input.js new file mode 100644 index 00000000000000..814f00a27b3fac --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/input.js @@ -0,0 +1,5 @@ +export function generateMetadata() {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.js new file mode 100644 index 00000000000000..2c532d7ab2b0c4 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.js @@ -0,0 +1,4 @@ +export function generateMetadata() {} +export default function() { + return null; +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.stderr b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.stderr new file mode 100644 index 00000000000000..ee9105e39d97a1 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/generate-metadata/output.stderr @@ -0,0 +1,8 @@ + x You are attempting to export "generateMetadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https:// + | nextjs.org/docs/app/api-reference/directives/use-client + | + | + ,-[input.js:1:1] + 1 | export function generateMetadata() {} + : ^^^^^^^^^^^^^^^^ + `---- diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/input.js new file mode 100644 index 00000000000000..89bd63dc88235f --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/input.js @@ -0,0 +1,5 @@ +export const metadata = {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.js new file mode 100644 index 00000000000000..4db14f97a7c5c9 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.js @@ -0,0 +1,4 @@ +export const metadata = {}; +export default function() { + return null; +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.stderr b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.stderr new file mode 100644 index 00000000000000..0111b7ded6f5e0 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/metadata/output.stderr @@ -0,0 +1,8 @@ + x You are attempting to export "metadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://nextjs.org/ + | docs/app/api-reference/directives/use-client + | + | + ,-[input.js:1:1] + 1 | export const metadata = {} + : ^^^^^^^^ + `---- diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/input.js new file mode 100644 index 00000000000000..1242c33bb24c2f --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/input.js @@ -0,0 +1,9 @@ +export const metadata = {} + +export function generateMetadata() {} + +export function getServerSideProps() {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.js new file mode 100644 index 00000000000000..4ef36e2e6482c0 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.js @@ -0,0 +1,6 @@ +export const metadata = {}; +export function generateMetadata() {} +export function getServerSideProps() {} +export default function() { + return null; +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.stderr b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.stderr new file mode 100644 index 00000000000000..4071d9fd5d0b86 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/client-graph/multiple/output.stderr @@ -0,0 +1,17 @@ + x You are attempting to export "getServerSideProps" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https:// + | nextjs.org/docs/app/api-reference/directives/use-client + | + | + ,-[input.js:5:1] + 4 | + 5 | export function getServerSideProps() {} + : ^^^^^^^^^^^^^^^^^^ + `---- + x "getServerSideProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching + | + | + ,-[input.js:5:1] + 4 | + 5 | export function getServerSideProps() {} + : ^^^^^^^^^^^^^^^^^^ + `---- diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/input.js new file mode 100644 index 00000000000000..a29d03c3c731ff --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/input.js @@ -0,0 +1,5 @@ +export const runtime = 'edge' +export const dynamic = 'force-dynamic' +export const dynamicParams = false +export const fetchCache = 'force-no-store' +export const revalidate = 1 diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.js new file mode 100644 index 00000000000000..115206754ba162 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.js @@ -0,0 +1,5 @@ +export const runtime = 'edge'; +export const dynamic = 'force-dynamic'; +export const dynamicParams = false; +export const fetchCache = 'force-no-store'; +export const revalidate = 1; diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.stderr b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.stderr new file mode 100644 index 00000000000000..968ba183218996 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/dynamic-io/output.stderr @@ -0,0 +1,30 @@ + x "fetchCache" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it. + ,-[input.js:5:1] + 4 | export const fetchCache = 'force-no-store' + 5 | export const revalidate = 1 + : ^^^^^^^^^^ + `---- + x "dynamic" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it. + ,-[input.js:5:1] + 4 | export const fetchCache = 'force-no-store' + 5 | export const revalidate = 1 + : ^^^^^^^^^^ + `---- + x "dynamicParams" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it. + ,-[input.js:5:1] + 4 | export const fetchCache = 'force-no-store' + 5 | export const revalidate = 1 + : ^^^^^^^^^^ + `---- + x "revalidate" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it. + ,-[input.js:5:1] + 4 | export const fetchCache = 'force-no-store' + 5 | export const revalidate = 1 + : ^^^^^^^^^^ + `---- + x "runtime" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it. + ,-[input.js:5:1] + 4 | export const fetchCache = 'force-no-store' + 5 | export const revalidate = 1 + : ^^^^^^^^^^ + `---- diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/input.js new file mode 100644 index 00000000000000..3bfb37b61950e0 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/input.js @@ -0,0 +1,6 @@ +// generateMetadata without metadata is ok. +export function generateMetadata() {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/output.js new file mode 100644 index 00000000000000..3a60dea5577a7b --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/generate-metadata/output.js @@ -0,0 +1,5 @@ +// generateMetadata without metadata is ok. +export function generateMetadata() {} +export default function() { + return null; +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/input.js new file mode 100644 index 00000000000000..43844518478a15 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/input.js @@ -0,0 +1,7 @@ +export const metadata = {} + +export function generateMetadata() {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.js new file mode 100644 index 00000000000000..9d93d28be45ecf --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.js @@ -0,0 +1,5 @@ +export const metadata = {}; +export function generateMetadata() {} +export default function() { + return null; +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.stderr b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.stderr new file mode 100644 index 00000000000000..a2731ea543f571 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata-conflict/output.stderr @@ -0,0 +1,8 @@ + x "metadata" and "generateMetadata" cannot be exported at the same time, please keep one of them. Read more: https://nextjs.org/docs/app/api-reference/file-conventions/metadata + | + | + ,-[input.js:3:1] + 2 | + 3 | export function generateMetadata() {} + : ^^^^^^^^^^^^^^^^ + `---- diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/input.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/input.js new file mode 100644 index 00000000000000..916b65ee700326 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/input.js @@ -0,0 +1,6 @@ +// metadata without generateMetadata is ok. +export const metadata = {} + +export default function () { + return null +} diff --git a/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/output.js b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/output.js new file mode 100644 index 00000000000000..847f0386da9230 --- /dev/null +++ b/crates/next-custom-transforms/tests/errors/react-server-components/server-graph/metadata/output.js @@ -0,0 +1,5 @@ +// metadata without generateMetadata is ok. +export const metadata = {}; +export default function() { + return null; +}