Skip to content

Commit 4aa57ed

Browse files
authored
chore: standardise ODB terminology (#1641)
* chore: make odb terminology consistent * test: update tests with new odb headers * chore: add note about minimum ODB TTL * fix: revert revalidate to 1 for test purposes * test: updates tests with new header key * test: fix dynamic route tests to use debug headers
1 parent 27ef2d1 commit 4aa57ed

File tree

4 files changed

+80
-55
lines changed

4 files changed

+80
-55
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ If you are using Nx, then you will need to point `publish` to the folder inside
6262
The Next.js Runtime fully supports ISR on Netlify. For more details see
6363
[the ISR docs](https://github.com/netlify/next-runtime/blob/main/docs/isr.md).
6464

65+
Note that Netlify has a minimum TTL of 60 seconds for revalidation.
66+
6567
## Use with `next export`
6668

6769
If you are using `next export` to generate a static site, you do not need most of the functionality of this Next.js
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,149 @@
1+
/* eslint-disable max-lines-per-function */
12
describe('Static Routing', () => {
23
it('renders correct page via SSR on a static route', () => {
3-
cy.request('/getServerSideProps/static/').then((res) => {
4+
cy.request({ url: '/getServerSideProps/static/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
45
expect(res.status).to.eq(200)
5-
expect(res.headers).to.have.property('x-render-mode', 'ssr')
6+
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
67
expect(res.body).to.contain('Sleepy Hollow')
78
})
89
})
910
it('serves correct static file on a static route', () => {
10-
cy.request('/getStaticProps/static/').then((res) => {
11+
cy.request({ url: '/getStaticProps/static/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
1112
expect(res.status).to.eq(200)
12-
expect(res.headers).to.not.have.property('x-render-mode')
13+
expect(res.headers).to.not.have.property('x-nf-render-mode')
1314
expect(res.body).to.contain('Dancing with the Stars')
1415
})
1516
})
1617
it('renders correct page via ODB on a static route', () => {
17-
cy.request('/getStaticProps/with-revalidate/').then((res) => {
18+
cy.request({ url: '/getStaticProps/with-revalidate/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
1819
expect(res.status).to.eq(200)
19-
expect(res.headers).to.have.property('x-render-mode', 'isr')
20+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=1')
2021
expect(res.body).to.contain('Dancing with the Stars')
2122
})
2223
})
2324
})
2425

2526
describe('Dynamic Routing', () => {
2627
it('renders correct page via SSR on a dynamic route', () => {
27-
cy.request('/getServerSideProps/1/').then((res) => {
28+
cy.request({ url: '/getServerSideProps/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
2829
expect(res.status).to.eq(200)
29-
expect(res.headers).to.have.property('x-render-mode', 'ssr')
30+
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
3031
expect(res.body).to.contain('Under the Dome')
3132
})
3233
})
3334
it('renders correct page via SSR on a dynamic catch-all route', () => {
34-
cy.request('/getServerSideProps/all/1/').then((res) => {
35+
cy.request({ url: '/getServerSideProps/all/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
3536
expect(res.status).to.eq(200)
36-
expect(res.headers).to.have.property('x-render-mode', 'ssr')
37+
expect(res.headers).to.have.property('x-nf-render-mode', 'ssr')
3738
expect(res.body).to.contain('Under the Dome')
3839
})
3940
})
4041
it('serves correct static file on a prerendered dynamic route with fallback: false', () => {
41-
cy.request('/getStaticProps/1/').then((res) => {
42+
cy.request({ url: '/getStaticProps/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
4243
expect(res.status).to.eq(200)
43-
expect(res.headers).to.not.have.property('x-render-mode')
44+
expect(res.headers).to.not.have.property('x-nf-render-mode')
4445
expect(res.body).to.contain('Under the Dome')
4546
})
4647
})
4748
it('renders custom 404 on a non-prerendered dynamic route with fallback: false', () => {
48-
cy.request({ url: '/getStaticProps/3/', failOnStatusCode: false }).then((res) => {
49-
expect(res.status).to.eq(404)
50-
expect(res.headers).to.have.property('x-render-mode', 'odb')
51-
expect(res.body).to.contain('Custom 404')
52-
})
49+
cy.request({ url: '/getStaticProps/3/', headers: { 'x-nf-debug-logging': '1' }, failOnStatusCode: false }).then(
50+
(res) => {
51+
expect(res.status).to.eq(404)
52+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
53+
expect(res.body).to.contain('Custom 404')
54+
},
55+
)
5356
})
5457
it('serves correct static file on a prerendered dynamic route with fallback: true', () => {
55-
cy.request('/getStaticProps/withFallback/1/').then((res) => {
58+
cy.request({ url: '/getStaticProps/withFallback/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
5659
expect(res.status).to.eq(200)
57-
expect(res.headers).to.not.have.property('x-render-mode')
60+
expect(res.headers).to.not.have.property('x-nf-render-mode')
5861
expect(res.body).to.contain('Under the Dome')
5962
})
6063
})
6164
it('renders fallback page via ODB on a non-prerendered dynamic route with fallback: true', () => {
62-
cy.request('/getStaticProps/withFallback/3/').then((res) => {
65+
cy.request({ url: '/getStaticProps/withFallback/3/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
6366
expect(res.status).to.eq(200)
6467
// expect 'odb' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
65-
expect(res.headers).to.have.property('x-render-mode', 'odb')
68+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
6669
// expect 'Bitten' until the above is fixed and we can test for fallback 'Loading...' message
6770
expect(res.body).to.contain('Bitten')
6871
})
6972
})
7073
it('serves correct static file on a prerendered dynamic route with fallback: blocking', () => {
71-
cy.request('/getStaticProps/withFallbackBlocking/1/').then((res) => {
72-
expect(res.status).to.eq(200)
73-
expect(res.headers).to.not.have.property('x-render-mode')
74-
expect(res.body).to.contain('Under the Dome')
75-
})
74+
cy.request({ url: '/getStaticProps/withFallbackBlocking/1/', headers: { 'x-nf-debug-logging': '1' } }).then(
75+
(res) => {
76+
expect(res.status).to.eq(200)
77+
expect(res.headers).to.not.have.property('x-nf-render-mode')
78+
expect(res.body).to.contain('Under the Dome')
79+
},
80+
)
7681
})
7782
it('renders correct page via ODB on a non-prerendered dynamic route with fallback: blocking', () => {
78-
cy.request('/getStaticProps/withFallbackBlocking/3/').then((res) => {
79-
expect(res.status).to.eq(200)
80-
expect(res.headers).to.have.property('x-render-mode', 'odb')
81-
expect(res.body).to.contain('Bitten')
82-
})
83+
cy.request({ url: '/getStaticProps/withFallbackBlocking/3/', headers: { 'x-nf-debug-logging': '1' } }).then(
84+
(res) => {
85+
expect(res.status).to.eq(200)
86+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
87+
expect(res.body).to.contain('Bitten')
88+
},
89+
)
8390
})
8491
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: false', () => {
85-
cy.request('/getStaticProps/withRevalidate/1/').then((res) => {
92+
cy.request({ url: '/getStaticProps/withRevalidate/1/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => {
8693
expect(res.status).to.eq(200)
87-
expect(res.headers).to.have.property('x-render-mode', 'isr')
94+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
8895
expect(res.body).to.contain('Under the Dome')
8996
})
9097
})
9198
it('renders custom 404 on a non-prerendered dynamic route with revalidate and fallback: false', () => {
92-
cy.request({ url: '/getStaticProps/withRevalidate/3/', failOnStatusCode: false }).then((res) => {
99+
cy.request({
100+
url: '/getStaticProps/withRevalidate/3/',
101+
headers: { 'x-nf-debug-logging': '1' },
102+
failOnStatusCode: false,
103+
}).then((res) => {
93104
expect(res.status).to.eq(404)
94-
expect(res.headers).to.have.property('x-render-mode', 'odb')
105+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb')
95106
expect(res.body).to.contain('Custom 404')
96107
})
97108
})
98109
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: true', () => {
99-
cy.request('/getStaticProps/withRevalidate/withFallback/1/').then((res) => {
100-
expect(res.status).to.eq(200)
101-
expect(res.headers).to.have.property('x-render-mode', 'isr')
102-
expect(res.body).to.contain('Under the Dome')
103-
})
110+
cy.request({ url: '/getStaticProps/withRevalidate/withFallback/1/', headers: { 'x-nf-debug-logging': '1' } }).then(
111+
(res) => {
112+
expect(res.status).to.eq(200)
113+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
114+
expect(res.body).to.contain('Under the Dome')
115+
},
116+
)
104117
})
105118
it('renders fallback page via ODB on a non-prerendered dynamic route with revalidate and fallback: true', () => {
106-
cy.request('/getStaticProps/withRevalidate/withFallback/3/').then((res) => {
107-
expect(res.status).to.eq(200)
108-
expect(res.headers).to.have.property('x-render-mode', 'isr')
109-
// expect 'Bitten' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
110-
expect(res.body).to.contain('Bitten')
111-
})
119+
cy.request({ url: '/getStaticProps/withRevalidate/withFallback/3/', headers: { 'x-nf-debug-logging': '1' } }).then(
120+
(res) => {
121+
expect(res.status).to.eq(200)
122+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
123+
// expect 'Bitten' until https://github.com/netlify/pillar-runtime/issues/438 is fixed
124+
expect(res.body).to.contain('Bitten')
125+
},
126+
)
112127
})
113128
it('renders correct page via ODB on a prerendered dynamic route with revalidate and fallback: blocking', () => {
114-
cy.request('/getStaticProps/withRevalidate/withFallbackBlocking/1/').then((res) => {
129+
cy.request({
130+
url: '/getStaticProps/withRevalidate/withFallbackBlocking/1/',
131+
headers: { 'x-nf-debug-logging': '1' },
132+
}).then((res) => {
115133
expect(res.status).to.eq(200)
116-
expect(res.headers).to.have.property('x-render-mode', 'isr')
134+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
117135
expect(res.body).to.contain('Under the Dome')
118136
})
119137
})
120138
it('renders correct page via ODB on a non-prerendered dynamic route with revalidate and fallback: blocking', () => {
121-
cy.request('/getStaticProps/withRevalidate/withFallbackBlocking/3/').then((res) => {
139+
cy.request({
140+
url: '/getStaticProps/withRevalidate/withFallbackBlocking/3/',
141+
headers: { 'x-nf-debug-logging': '1' },
142+
}).then((res) => {
122143
expect(res.status).to.eq(200)
123-
expect(res.headers).to.have.property('x-render-mode', 'isr')
144+
expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60')
124145
expect(res.body).to.contain('Bitten')
125146
})
126147
})
127148
})
149+
/* eslint-enable max-lines-per-function */

demos/default/pages/getStaticProps/with-revalidate.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function getStaticProps(context) {
2525
props: {
2626
show: data,
2727
},
28+
// ODB handler will use the minimum TTL=60s
2829
revalidate: 1,
2930
}
3031
}

packages/runtime/src/templates/getHandler.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ const makeHandler = (conf: NextConfig, app, pageRoot, staticManifest: Array<[str
129129
// Long-expiry TTL is basically no TTL, so we'll skip it
130130
if (ttl > 0 && ttl < ONE_YEAR_IN_SECONDS) {
131131
result.ttl = ttl
132-
requestMode = 'isr'
132+
requestMode = `odb ttl=${ttl}`
133133
}
134134
}
135135
multiValueHeaders['cache-control'] = ['public, max-age=0, must-revalidate']
136136
}
137-
multiValueHeaders['x-render-mode'] = [requestMode]
138-
console.log(
139-
`[${event.httpMethod}] ${event.path} (${requestMode?.toUpperCase()}${result.ttl > 0 ? ` ${result.ttl}s` : ''})`,
140-
)
137+
multiValueHeaders['x-nf-render-mode'] = [requestMode]
138+
139+
console.log(`[${event.httpMethod}] ${event.path} (${requestMode?.toUpperCase()})`)
140+
141141
return {
142142
...result,
143143
multiValueHeaders,

0 commit comments

Comments
 (0)