Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test fixtures demonstrating export statement validation bugs #75277

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 11 additions & 76 deletions crates/next-custom-transforms/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,20 @@ 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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fly-by refactor to combine the server-graph and client-graph tests. Their config is identical apart from is_react_server_layer, which we now derive from the input path, i.e. by checking whether server-graph is included in the path.

use next_custom_transforms::transforms::react_server_components::{Config, Options};
let is_react_server_layer = input.iter().any(|s| s.to_str() == Some("server-graph"));
let dynamic_io_enabled = input.iter().any(|s| s.to_str() == Some("dynamic-io"));
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|tr| {
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,
Expand Down Expand Up @@ -164,50 +139,10 @@ fn next_font_loaders_errors(input: PathBuf) {
);
}

#[fixture("tests/errors/server-actions/server-graph/**/input.js")]
fn react_server_actions_server_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| {
(
resolver(Mark::new(), Mark::new(), false),
server_components(
FileName::Real(PathBuf::from("/app/item.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: true,
dynamic_io_enabled: true,
}),
tr.comments.as_ref().clone(),
None,
),
server_actions(
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: true,
use_cache_enabled: true,
hash_salt: "".into(),
cache_kinds: FxHashSet::default(),
},
tr.comments.as_ref().clone(),
Default::default(),
),
)
},
&input,
&output,
FixtureTestConfig {
allow_error: true,
module: Some(true),
..Default::default()
},
);
}

#[fixture("tests/errors/server-actions/client-graph/**/input.js")]
fn react_server_actions_client_errors(input: PathBuf) {
#[fixture("tests/errors/server-actions/**/input.js")]
fn react_server_actions_errors(input: PathBuf) {
use next_custom_transforms::transforms::react_server_components::{Config, Options};
let is_react_server_layer = input.iter().any(|s| s.to_str() == Some("server-graph"));
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
Expand All @@ -217,7 +152,7 @@ fn react_server_actions_client_errors(input: PathBuf) {
server_components(
FileName::Real(PathBuf::from("/app/item.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: false,
is_react_server_layer,
dynamic_io_enabled: true,
}),
tr.comments.as_ref().clone(),
Expand All @@ -226,7 +161,7 @@ fn react_server_actions_client_errors(input: PathBuf) {
server_actions(
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: false,
is_react_server_layer,
use_cache_enabled: true,
hash_salt: "".into(),
cache_kinds: FxHashSet::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function generateMetadata() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -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() {}
: ^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const metadata = {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const metadata = {};
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -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 = {}
: ^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const metadata = {}

export function generateMetadata() {}

export function getServerSideProps() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const metadata = {};
export function generateMetadata() {}
export function getServerSideProps() {}
export default function() {
return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is completely off. getServerSideProps is logged twice with different messages (the first one being wrong), and the two metadata export messages are missing.

Original file line number Diff line number Diff line change
@@ -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() {}
: ^^^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All five issues incorrectly report the revalidate export statement as the source instead of their respective statements. The order is also not as it occurs in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the reported issues is currently non-deterministic, which may lead to the react_server_components_errors_tests__errors__react_server_components__server_graph__dynamic_io__input_js test failing in CI. This will be fixed in the next PR in the stack.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 "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 "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 "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
: ^^^^^^^^^^
`----
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
: ^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// generateMetadata without metadata is ok.
export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// generateMetadata without metadata is ok.
export function generateMetadata() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const metadata = {}

export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const metadata = {};
export function generateMetadata() {}
export default function() {
return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally highlight both export statements.

Original file line number Diff line number Diff line change
@@ -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() {}
: ^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// metadata without generateMetadata is ok.
export const metadata = {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// metadata without generateMetadata is ok.
export const metadata = {};
export default function() {
return null;
}
Loading
Loading