Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Dynamic Usage Error when using previewData with generateStaticPa…
…rams and appDir
- Loading branch information
1 parent
c4b6bb8
commit ce52d11
Showing
5 changed files
with
69 additions
and
6 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,30 @@ | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import path from 'path' | ||
import webdriver from 'next-webdriver' | ||
|
||
describe('app-dir previewData with SSG', () => { | ||
if ((global as any).isNextDeploy) { | ||
it('should skip next deploy for now', () => {}) | ||
return | ||
} | ||
|
||
let next: NextInstance | ||
|
||
afterAll(() => next.destroy()) | ||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: new FileRef(path.join(__dirname, 'app-preview-static')), | ||
}) | ||
}) | ||
|
||
it('Should not throw Dynamic Server Usage error when using generateStaticParams with previewData', async () => { | ||
const browserOnIndexPage = await webdriver(next.url, '/') | ||
|
||
const content = await browserOnIndexPage | ||
.elementByCss('#preview-data') | ||
.text() | ||
|
||
expect(content).toContain('previewData') | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
test/e2e/app-dir/app-preview-static/app/[[...route]]/page.js
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,29 @@ | ||
import { previewData } from 'next/headers' | ||
|
||
export default function Page() { | ||
const previewDataResult = previewData() | ||
|
||
return ( | ||
<main> | ||
<pre id="preview-data"> | ||
{JSON.stringify({ previewData: previewDataResult })} | ||
</pre> | ||
</main> | ||
) | ||
} | ||
|
||
export const generateStaticParams = async () => { | ||
const paths = [ | ||
{ | ||
route: [''], | ||
}, | ||
{ | ||
route: ['test'], | ||
}, | ||
{ | ||
route: ['test-2'], | ||
}, | ||
] | ||
|
||
return paths | ||
} |
5 changes: 3 additions & 2 deletions
5
test/e2e/app-dir/app-static/app/layout.js → .../app-dir/app-preview-static/app/layout.js
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,7 @@ | ||
const nextConfig = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |