forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore fully dynamic requests on server side (vercel#62949)
### What? make sure that we don't error for dynamic requests on server side. It will throw at runtime when using a dynamic request. ### Why? Not all packages are fully bundler compatible, but still work when only using the parts that work. We don't want to block users from using them by having an hard compile error. ### How? Closes PACK-2675
- Loading branch information
Showing
6 changed files
with
62 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function GET() { | ||
if (Math.random() < 0) dynamic() | ||
return new Response('Hello World') | ||
} | ||
|
||
function dynamic() { | ||
const dynamic = Math.random() + '' | ||
require(dynamic) | ||
import(dynamic) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default async function Page() { | ||
if (Math.random() < 0) dynamic() | ||
return <p>Hello World</p> | ||
} | ||
|
||
function dynamic() { | ||
const dynamic = Math.random() + '' | ||
require(dynamic) | ||
import(dynamic) | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/dynamic-requests/dynamic-requests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('dynamic-requests', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not error for dynamic requests in pages', async () => { | ||
const $ = await next.render$('/') | ||
expect($('p').text()).toBe('Hello World') | ||
}) | ||
|
||
it('should not error for dynamic requests in routes', async () => { | ||
const res = await next.fetch('/hello') | ||
const html = await res.text() | ||
expect(html).toContain('Hello World') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |