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 3 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
12 changes: 6 additions & 6 deletions cypress/integration/default/dynamic-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Static Routing', () => {
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-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Dancing with the Stars')
})
})
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Dynamic Routing', () => {
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-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Under the Dome')
})
})
Expand All @@ -98,29 +98,29 @@ describe('Dynamic Routing', () => {
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-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-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-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-render-mode', 'odb ttl=60')
expect(res.body).to.contain('Bitten')
})
})
Expand Down
2 changes: 1 addition & 1 deletion demos/default/pages/getStaticProps/with-revalidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getStaticProps(context) {
props: {
show: data,
},
revalidate: 1,
revalidate: 60,

Choose a reason for hiding this comment

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

A comment linking to documentation about the 60 second minimum would be helpful for folks navigating through the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I popped a note in the readme because there are various different demo pages with revalidate: 60 and thought it best not to duplicate the comment everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may have been deliberately set to 1 to check that it's correctly being changed to 60.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ascorbic ah, i see - i'll change it back and add a comment

}
}

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