-
Notifications
You must be signed in to change notification settings - Fork 86
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
Changes from all 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 ce6c963
chore: correct redirects
ascorbic 47ca397
test: add e2e test
ascorbic bfec635
chore: fix test
ascorbic 2f69d45
Merge branch 'main' into mk/rsc-no-isr
ascorbic 9be9286
ci: don't run tests against 14, because appDir requires 16
ascorbic 19cba0d
chore: snapidoo :tada:
ascorbic 10c9586
Merge branch 'main' into mk/rsc-no-isr
ascorbic 10b7984
ci: node 16
ascorbic c35de7b
ci: use node 16
ascorbic e7f205d
ci: normalise chunk names
ascorbic 2a1442f
ci: typo in test
ascorbic 1d5b887
chore: use repo next version
ascorbic f727d2f
chore: fix cypress test
ascorbic 8c057fe
test: temporarily remove esm for app alias
ascorbic 1fed222
chore: disable test failures
ascorbic 9e1d596
chore: move disabled test
ascorbic 846a307
chore: use EF to route RSC data reqs
ascorbic 1de5ddc
chore: fix test
ascorbic 47fb1e3
chore: fix test
ascorbic d36fff0
chore: fix cypress test
ascorbic c21de0e
chore: logging
ascorbic 2404c79
fix: handle trailing slash
ascorbic aaa7805
chore: wip
ascorbic 03fa2d0
Merge branch 'main' into mk/rsc-no-isr
ascorbic 0f81eab
chore: handle dynamic isr routes
ascorbic cc1cc9a
test: add more cypress tests
ascorbic 7faf80d
fix: handle localised RSC routes
ascorbic a0db05f
Merge branch 'main' into mk/rsc-no-isr
ascorbic 2a02c87
chore: simplify trailing slash handling
ascorbic f46be95
fix: correctly handle prerendered dynamic RSC routes
ascorbic f1ae602
test: fix cypress assertion
ascorbic 85aed59
fix: correct regex matcher
ascorbic f5f975f
test: fix cypress
ascorbic 82ff851
test: stop cypress following redirects
ascorbic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,32 +15,19 @@ jobs: | |
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
node-version: [14, '*'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -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' | ||
|
@@ -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 |
This file contains hidden or 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,77 @@ | ||
describe('appDir', () => { | ||
it('renders ISR appdir pages as HTML by default', () => { | ||
cy.request({ url: '/blog/erica/', followRedirect: false }).then((response) => { | ||
expect(response.headers['content-type']).to.match(/^text\/html/) | ||
}) | ||
}) | ||
|
||
it('renders static appdir pages as HTML by default', () => { | ||
cy.request({ url: '/blog/erica/first-post/', followRedirect: false }).then((response) => { | ||
expect(response.headers['content-type']).to.match(/^text\/html/) | ||
}) | ||
}) | ||
|
||
it('renders dynamic appdir pages as HTML by default', () => { | ||
cy.request({ url: '/blog/erica/random-post/', followRedirect: false }).then((response) => { | ||
expect(response.headers['content-type']).to.match(/^text\/html/) | ||
}) | ||
}) | ||
|
||
it('returns RSC data for RSC requests to ISR pages', () => { | ||
cy.request({ | ||
url: '/blog/erica/', | ||
headers: { | ||
RSC: '1', | ||
}, | ||
followRedirect: false, | ||
}).then((response) => { | ||
expect(response.headers).to.have.property('content-type', 'application/octet-stream') | ||
}) | ||
}) | ||
|
||
it('returns RSC data for RSC requests to static pages', () => { | ||
cy.request({ | ||
url: '/blog/erica/first-post/', | ||
headers: { | ||
RSC: '1', | ||
}, | ||
followRedirect: false, | ||
}).then((response) => { | ||
expect(response.headers).to.have.property('content-type', 'application/octet-stream') | ||
}) | ||
}) | ||
|
||
it('returns RSC data for RSC requests to dynamic pages', () => { | ||
cy.request({ | ||
url: '/blog/erica/random-post/', | ||
headers: { | ||
RSC: '1', | ||
}, | ||
followRedirect: false, | ||
}).then((response) => { | ||
expect(response.headers).to.have.property('content-type', 'application/octet-stream') | ||
}) | ||
}) | ||
|
||
it('correctly redirects HTML requests for ISR pages', () => { | ||
cy.request({ url: '/blog/erica', followRedirect: false }).then((response) => { | ||
expect(response.status).to.equal(308) | ||
expect(response.headers).to.have.property('location', '/blog/erica/') | ||
}) | ||
}) | ||
|
||
// This needs trailing slash handling to be fixed | ||
it.skip('correctly redirects HTML requests for static pages', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prerendered pages do the normal Netlify trailing slash handling. This shoudl work once we have the trialing slash edge funciton |
||
cy.request({ url: '/blog/erica/first-post', followRedirect: false }).then((response) => { | ||
expect(response.status).to.equal(308) | ||
expect(response.headers).to.have.property('location', '/blog/erica/first-post/') | ||
}) | ||
}) | ||
|
||
it('correctly redirects HTML requests for dynamic pages', () => { | ||
cy.request({ url: '/blog/erica/random-post', followRedirect: false }).then((response) => { | ||
expect(response.status).to.equal(308) | ||
expect(response.headers).to.have.property('location', '/blog/erica/random-post/') | ||
}) | ||
}) | ||
}) |
This file contains hidden or 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,4 @@ | ||
{ | ||
"typescript.tsdk": "../../node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
This file contains hidden or 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,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}`) | ||
} | ||
} | ||
} |
This file contains hidden or 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,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' }] | ||
} |
This file contains hidden or 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,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 /> | ||
</> | ||
) | ||
} |
This file contains hidden or 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 function Layout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<title>my static blog</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -84,5 +84,6 @@ module.exports = { | |
}, | ||
experimental: { | ||
optimizeCss: false, | ||
appDir: true, | ||
}, | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run tests with the same version of next as the repo