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
3 changes: 2 additions & 1 deletion crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ pub async fn get_server_module_options_context(

next_server_rules.extend(common_next_server_rules.iter().cloned());
internal_custom_rules.extend(common_next_server_rules);
foreign_next_server_rules.extend(internal_custom_rules.clone());

let module_options_context = ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
Expand All @@ -854,7 +855,7 @@ pub async fn get_server_module_options_context(
..module_options_context
};
let foreign_code_module_options_context = ModuleOptionsContext {
module_rules: internal_custom_rules.clone(),
module_rules: foreign_next_server_rules.clone(),
enable_webpack_loaders: foreign_enable_webpack_loaders,
// NOTE(WEB-1016) PostCSS transforms should also apply to foreign code.
enable_postcss_transform: enable_foreign_postcss_transform,
Expand Down
14 changes: 4 additions & 10 deletions test/e2e/app-dir/use-cache/app/(partially-static)/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { cacheLife } from 'next/cache'

async function getCachedRandom(n: number) {
'use cache'
cacheLife('weeks')
return String(Math.ceil(Math.random() * n))
}
import { getCachedRandomWithCacheLife } from 'my-pkg'

export async function generateStaticParams() {
return [
{ id: `a${await getCachedRandom(9)}` },
{ id: `b${await getCachedRandom(2)}` },
{ id: `a${await getCachedRandomWithCacheLife(9)}` },
{ id: `b${await getCachedRandomWithCacheLife(2)}` },
]
}

export default async function Page() {
const value = getCachedRandom(1)
const value = getCachedRandomWithCacheLife(1)

return <p>{value}</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getCachedRandomWithCacheLife } from 'my-pkg'
import { NextRequest } from 'next/server'

export async function generateStaticParams() {
return [{ id: await getCachedRandomWithCacheLife() }]
}

export async function GET(
req: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params

return Response.json({ id })
}
13 changes: 3 additions & 10 deletions test/e2e/app-dir/use-cache/app/(partially-static)/api/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { cacheTag } from 'next/cache'

async function getCachedRandom() {
'use cache'
cacheTag('api')

return Math.random()
}
import { getCachedRandomWithTag } from 'my-pkg'

export async function GET() {
const rand1 = await getCachedRandom()
const rand2 = await getCachedRandom()
const rand1 = await getCachedRandomWithTag('api')
const rand2 = await getCachedRandomWithTag('api')

return Response.json({ rand1, rand2 })
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/use-cache/node_modules/my-pkg/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/e2e/app-dir/use-cache/use-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ describe('use-cache', () => {
// [id] route, first entry in generateStaticParams
expect.stringMatching(/\/a\d/),
withCacheComponents && '/api',
// api/[id] route handler using generateStaticParams with 'use cache' from node_modules
expect.stringMatching(/\/api\/\d/),
// [id] route, second entry in generateStaticParams
expect.stringMatching(/\/b\d/),
'/cache-fetch',
Expand Down
Loading