Skip to content

fix: correctly handle ISR for appDir pages #1855

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

Merged
merged 35 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
45c6526
fix: don't use ISR for appDir pages
ascorbic Dec 22, 2022
ce6c963
chore: correct redirects
ascorbic Dec 22, 2022
47ca397
test: add e2e test
ascorbic Dec 22, 2022
bfec635
chore: fix test
ascorbic Dec 22, 2022
2f69d45
Merge branch 'main' into mk/rsc-no-isr
ascorbic Jan 3, 2023
9be9286
ci: don't run tests against 14, because appDir requires 16
ascorbic Jan 3, 2023
19cba0d
chore: snapidoo :tada:
ascorbic Jan 3, 2023
10c9586
Merge branch 'main' into mk/rsc-no-isr
ascorbic Jan 3, 2023
10b7984
ci: node 16
ascorbic Jan 3, 2023
c35de7b
ci: use node 16
ascorbic Jan 3, 2023
e7f205d
ci: normalise chunk names
ascorbic Jan 3, 2023
2a1442f
ci: typo in test
ascorbic Jan 3, 2023
1d5b887
chore: use repo next version
ascorbic Jan 3, 2023
f727d2f
chore: fix cypress test
ascorbic Jan 4, 2023
8c057fe
test: temporarily remove esm for app alias
ascorbic Jan 4, 2023
1fed222
chore: disable test failures
ascorbic Jan 5, 2023
9e1d596
chore: move disabled test
ascorbic Jan 5, 2023
846a307
chore: use EF to route RSC data reqs
ascorbic Jan 6, 2023
1de5ddc
chore: fix test
ascorbic Jan 6, 2023
47fb1e3
chore: fix test
ascorbic Jan 8, 2023
d36fff0
chore: fix cypress test
ascorbic Jan 8, 2023
c21de0e
chore: logging
ascorbic Jan 9, 2023
2404c79
fix: handle trailing slash
ascorbic Jan 9, 2023
aaa7805
chore: wip
ascorbic Jan 11, 2023
03fa2d0
Merge branch 'main' into mk/rsc-no-isr
ascorbic Jan 12, 2023
0f81eab
chore: handle dynamic isr routes
ascorbic Jan 12, 2023
cc1cc9a
test: add more cypress tests
ascorbic Jan 12, 2023
7faf80d
fix: handle localised RSC routes
ascorbic Jan 13, 2023
a0db05f
Merge branch 'main' into mk/rsc-no-isr
ascorbic Jan 13, 2023
2a02c87
chore: simplify trailing slash handling
ascorbic Jan 13, 2023
f46be95
fix: correctly handle prerendered dynamic RSC routes
ascorbic Jan 13, 2023
f1ae602
test: fix cypress assertion
ascorbic Jan 13, 2023
85aed59
fix: correct regex matcher
ascorbic Jan 13, 2023
f5f975f
test: fix cypress
ascorbic Jan 13, 2023
82ff851
test: stop cypress following redirects
ascorbic Jan 13, 2023
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
29 changes: 2 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,19 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [14, '*']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AppDir requires 16+

exclude:
- os: macOS-latest
node-version: 14
- os: windows-latest
node-version: 14
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Installing with LTS Node.js
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
node-version: 16
check-latest: true
- name: NPM Install
run: npm install
- name: Switching to Node.js ${{ matrix.node-version }} to run tests
uses: actions/setup-node@v2
if: "${{ matrix.node-version != 'lts/*' }}"
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Linting
run: npm run format:ci
if: "${{ matrix.node-version == 'lts/*' }}"
- name: Run tests against next@latest
run: npm test
canary:
Expand All @@ -50,12 +37,6 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [14, '*']
exclude:
- os: macOS-latest
node-version: 14
- os: windows-latest
node-version: 14
fail-fast: false

if: github.ref_name == 'main'
Expand All @@ -64,17 +45,11 @@ jobs:
- name: Installing with LTS Node.js
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
node-version: 16
check-latest: true
- name: NPM Install
run: npm install
- name: Install Next.js Canary
run: npm install -D next@canary --legacy-peer-deps
- name: Switching to Node.js ${{ matrix.node-version }} to run tests
uses: actions/setup-node@v2
if: "${{ matrix.node-version != 'lts/*' }}"
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Run tests against next@canary
run: npm test
19 changes: 19 additions & 0 deletions cypress/integration/default/appdir.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('appDir', () => {
it('renders appdir pages using SSR', () => {
cy.request('/blog/erica/first-post/').then((response) => {
expect(response.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(response.headers).to.have.property('context-type', 'text/html; charset=utf-8')
})
})

it('returns RSC data for RSC requests', () => {
cy.request('/blog/erica/first-post/', {
Headers: {
RSC: '1',
},
}).then((response) => {
expect(response.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(response.headers).to.have.property('context-type', 'application/octet-stream')
})
})
})
60 changes: 60 additions & 0 deletions demos/default/app/blog/[author]/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { notFound } from 'next/navigation'

export const revalidate = null

export const dynamicParams = true

export default function Page({ params }) {
if (params.author === 'matt') {
return notFound()
}
return (
<>
<p id="page">/blog/[author]/[slug]</p>
<p id="params">{JSON.stringify(params)}</p>
<p id="date">{Date.now()}</p>
</>
)
}

export function generateStaticParams({ params }: any) {
console.log('/blog/[author]/[slug] generateStaticParams', JSON.stringify(params))

switch (params.author) {
case 'erica': {
return [
{
slug: 'first-post',
},
]
}
case 'sarah': {
return [
{
slug: 'second-post',
},
]
}
case 'nick': {
return [
{
slug: 'first-post',
},
{
slug: 'second-post',
},
]
}
case 'rob': {
return [
{
slug: 'second-post',
},
]
}

default: {
throw new Error(`unexpected author param received ${params.author}`)
}
}
}
14 changes: 14 additions & 0 deletions demos/default/app/blog/[author]/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function Layout({ children, params }) {
return (
<>
<p id="author-layout-params">{JSON.stringify(params)}</p>
{children}
</>
)
}

export function generateStaticParams(params) {
console.log('/blog/[author] generateStaticParams', JSON.stringify(params))

return [{ author: 'nick' }, { author: 'sarah' }, { author: 'rob' }, { author: 'erica' }]
}
39 changes: 39 additions & 0 deletions demos/default/app/blog/[author]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Link from 'next/link'

export default async function Page({ params }) {
await fetch('http://example.com', {
next: { revalidate: 10 },
})
return (
<>
<p id="page">/blog/[author]</p>
<p id="params">{JSON.stringify(params)}</p>
<p id="date">{Date.now()}</p>
<Link href="/blog/erica" id="author-1">
/blog/erica
</Link>
<br />
<Link href="/blog/sarah" id="author-2">
/blog/sarah
</Link>
<br />
<Link href="/blog/nick" id="author-3">
/blog/nick
</Link>
<br />

<Link href="/blog/erica/first-post" id="author-1-post-1">
/blog/erica/first-post
</Link>
<br />
<Link href="/blog/sarah/second-post" id="author-2-post-1">
/blog/sarah/second-post
</Link>
<br />
<Link href="/blog/nick/first-post" id="author-3-post-1">
/blog/nick/first-post
</Link>
<br />
</>
)
}
10 changes: 10 additions & 0 deletions demos/default/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function Layout({ children }) {
return (
<html lang="en">
<head>
<title>my static blog</title>
</head>
<body>{children}</body>
</html>
)
}
1 change: 1 addition & 0 deletions demos/default/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ module.exports = {
},
experimental: {
optimizeCss: false,
appDir: true,
},
}
6 changes: 6 additions & 0 deletions demos/default/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ const Index = ({ shows, nodeEnv }) => {
<Link href="/rewriteToStatic">Rewrite to static (should show getStaticProps/1)</Link>
</li>
</ul>
<h4>appDir</h4>
<ul>
<li>
<Link href="/blog/erica">app dir page</Link>
</li>
</ul>
<h4>Preview mode</h4>
<p>Preview mode: </p>
<ul>
Expand Down
12 changes: 9 additions & 3 deletions demos/default/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
}
Loading