Skip to content
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
12 changes: 10 additions & 2 deletions crates/next-custom-transforms/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,32 @@ fn next_ssg_errors(input: PathBuf) {
}

#[fixture("tests/errors/react-server-components/**/input.js")]
#[fixture("tests/errors/react-server-components/**/page.js")]
#[fixture("tests/errors/react-server-components/**/route.js")]
fn react_server_components_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 cache_components_enabled = input.iter().any(|s| s.to_str() == Some("cache-components"));
let use_cache_enabled = input.iter().any(|s| s.to_str() == Some("use-cache"));

let app_dir = input
.iter()
.position(|s| s.to_str() == Some("app-dir"))
.map(|pos| input.iter().take(pos + 1).collect());

let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/page.js")).into(),
FileName::Real(input.clone()).into(),
Config::WithOptions(Options {
is_react_server_layer,
cache_components_enabled,
use_cache_enabled,
}),
tr.comments.as_ref().clone(),
None,
app_dir.clone(),
)
},
&input,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { cacheLife } from 'next/cache'

export async function test() {
cacheLife('days')
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cacheLife } from 'next/cache';
export async function test() {
cacheLife('days');
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You're importing a component that needs "cacheLife". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { cacheLife } from 'next/cache'
: ^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { cacheTag } from 'next/cache'

export async function test() {
cacheTag('test')
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cacheTag } from 'next/cache';
export async function test() {
cacheTag('test');
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You're importing a component that needs "cacheTag". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:1:1]
1 | import { cacheTag } from 'next/cache'
: ^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a comment.

'use strict'

/**
* This is a comment.
*/

import { lang } from 'next/root-params'

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is a comment.
'use strict';
/**
* This is a comment.
*/ import { lang } from 'next/root-params';
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
x You're importing a component that needs "next/root-params". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:9:1]
8 |
9 | import { lang } from 'next/root-params'
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a comment.

'use strict'

/**
* This is a comment.
*/

import 'server-only'

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is a comment.
'use strict';
/**
* This is a comment.
*/ import 'server-only';
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
x You're importing a component that needs "server-only". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
| Learn more: https://nextjs.org/docs/app/building-your-application/rendering
|
|
,-[input.js:9:1]
8 |
9 | import 'server-only'
: ^^^^^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { cacheLife } from 'next/cache'

export async function test() {
cacheLife('days')
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cacheLife } from 'next/cache';
export async function test() {
cacheLife('days');
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You're importing a component that needs "cacheLife". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-
| application/rendering/server-components
|
|
,-[input.js:1:1]
1 | import { cacheLife } from 'next/cache'
: ^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { cacheTag } from 'next/cache'

export async function test() {
cacheTag('test')
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { cacheTag } from 'next/cache';
export async function test() {
cacheTag('test');
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You're importing a component that needs "cacheTag". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/app/building-your-
| application/rendering/server-components
|
|
,-[input.js:1:1]
1 | import { cacheTag } from 'next/cache'
: ^^^^^^^^
`----
Loading