Skip to content

chore: standardise ODB terminology #1641

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 7 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ If you are using Nx, then you will need to point `publish` to the folder inside
The Next.js Runtime fully supports ISR on Netlify. For more details see
[the ISR docs](https://github.com/netlify/next-runtime/blob/main/docs/isr.md).

Note that Netlify has a minimum TTL of 60 seconds for revalidation.

## Use with `next export`

If you are using `next export` to generate a static site, you do not need most of the functionality of this Next.js
Expand Down
34 changes: 17 additions & 17 deletions cypress/integration/default/dynamic-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ describe('Static Routing', () => {
it('renders correct page via SSR on a static route', () => {
cy.request('/getServerSideProps/static/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'ssr')
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Sleepy Hollow')
})
})
it('serves correct static file on a static route', () => {
cy.request('/getStaticProps/static/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-render-mode')
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Dancing with the Stars')
})
})
it('renders correct page via ODB on a static route', () => {
cy.request('/getStaticProps/with-revalidate/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Dancing with the Stars')
})
})
Expand All @@ -26,101 +26,101 @@ describe('Dynamic Routing', () => {
it('renders correct page via SSR on a dynamic route', () => {
cy.request('/getServerSideProps/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'ssr')
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders correct page via SSR on a dynamic catch-all route', () => {
cy.request('/getServerSideProps/all/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'ssr')
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
expect(res.body).to.contain('Under the Dome')
})
})
it('serves correct static file on a prerendered dynamic route with fallback: false', () => {
cy.request('/getStaticProps/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-render-mode')
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders custom 404 on a non-prerendered dynamic route with fallback: false', () => {
cy.request({ url: '/getStaticProps/3/', failOnStatusCode: false }).then((res) => {
expect(res.status).to.eq(404)
expect(res.headers).to.have.property('x-render-mode', 'odb')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Custom 404')
})
})
it('serves correct static file on a prerendered dynamic route with fallback: true', () => {
cy.request('/getStaticProps/withFallback/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-render-mode')
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders fallback page via ODB on a non-prerendered dynamic route with fallback: true', () => {
cy.request('/getStaticProps/withFallback/3/').then((res) => {
expect(res.status).to.eq(200)
// expect 'odb' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
expect(res.headers).to.have.property('x-render-mode', 'odb')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
// expect 'Bitten' until the above is fixed and we can test for fallback 'Loading...' message
expect(res.body).to.contain('Bitten')
})
})
it('serves correct static file on a prerendered dynamic route with fallback: blocking', () => {
cy.request('/getStaticProps/withFallbackBlocking/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.not.have.property('x-render-mode')
expect(res.headers).to.not.have.property('x-nf-render-mode')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders correct page via ODB on a non-prerendered dynamic route with fallback: blocking', () => {
cy.request('/getStaticProps/withFallbackBlocking/3/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'odb')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Bitten')
})
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: false', () => {
cy.request('/getStaticProps/withRevalidate/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders custom 404 on a non-prerendered dynamic route with revalidate and fallback: false', () => {
cy.request({ url: '/getStaticProps/withRevalidate/3/', failOnStatusCode: false }).then((res) => {
expect(res.status).to.eq(404)
expect(res.headers).to.have.property('x-render-mode', 'odb')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
expect(res.body).to.contain('Custom 404')
})
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: true', () => {
cy.request('/getStaticProps/withRevalidate/withFallback/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders fallback page via ODB on a non-prerendered dynamic route with revalidate and fallback: true', () => {
cy.request('/getStaticProps/withRevalidate/withFallback/3/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
// expect 'Bitten' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
expect(res.body).to.contain('Bitten')
})
})
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: blocking', () => {
cy.request('/getStaticProps/withRevalidate/withFallbackBlocking/1/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
it('renders correct page via ODB on a non-prerendered dynamic route with revalidate and fallback: blocking', () => {
cy.request('/getStaticProps/withRevalidate/withFallbackBlocking/3/').then((res) => {
expect(res.status).to.eq(200)
expect(res.headers).to.have.property('x-render-mode', 'isr')
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Bitten')
})
})
Expand Down
1 change: 1 addition & 0 deletions demos/default/pages/getStaticProps/with-revalidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function getStaticProps(context) {
props: {
show: data,
},
// ODB handler will use the minimum TTL=60s
revalidate: 1,
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/runtime/src/templates/getHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
// Long-expiry TTL is basically no TTL, so we'll skip it
if (ttl > 0 && ttl < ONE_YEAR_IN_SECONDS) {
result.ttl = ttl
requestMode = 'isr'
requestMode = `odb ttl=${ttl}`
}
}
multiValueHeaders['cache-control'] = ['public, max-age=0, must-revalidate']
}
multiValueHeaders['x-render-mode'] = [requestMode]
console.log(
`[${event.httpMethod}] ${event.path} (${requestMode?.toUpperCase()}${result.ttl > 0 ? ` ${result.ttl}s` : ''})`,
)
multiValueHeaders['x-nf-render-mode'] = [requestMode]

console.log(`[${event.httpMethod}] ${event.path} (${requestMode?.toUpperCase()})`)

Choose a reason for hiding this comment

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

Was this console.log added for debugging purposes and accidentally added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks but nope - this is by design so that the ODB request is logged in the function logs


return {
...result,
multiValueHeaders,
Expand Down