Skip to content

Commit e18de13

Browse files
authored
fix: fixes an issue where the static pages could not be retrieved from the blob store (#79)
* fix: fixes an issue where the static pages could not be retrieved from the blob store * chore: update * chore: update * chore: update
1 parent f8eafe0 commit e18de13

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

.github/workflows/run-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
e2e:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111
- name: 'Install Node'
1212
uses: actions/setup-node@v3
1313
with:

playwright.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default defineConfig({
2121
baseURL: process.env.URL,
2222
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
2323
trace: 'on-first-retry',
24+
extraHTTPHeaders: {
25+
/* Add debug logging for netlify cache headers */
26+
'x-nf-debug-logging': '1',
27+
},
2428
},
2529
timeout: 10 * 60 * 1000,
2630
/* Configure projects for major browsers */

src/run/handlers/cache.cts

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ module.exports = class NetlifyCacheHandler implements CacheHandler {
152152
console.warn(`Failed to update tag manifest for ${tag}`, error)
153153
}
154154

155-
purgeCache({ tags: [tag] }).catch(() => {
156-
// noop
155+
purgeCache({ tags: [tag] }).catch((error) => {
156+
// TODO: add reporting here
157+
console.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`, error)
157158
})
158159
}
159160

src/run/handlers/next.cts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { join, relative } from 'path'
22
import fs from 'fs/promises'
3+
import { getDeployStore } from '@netlify/blobs'
34

45
import type { getRequestHandlers } from 'next/dist/server/lib/start-server.js'
56

@@ -9,7 +10,7 @@ import { patchFs } from 'fs-monkey'
910
type FS = typeof import('fs')
1011

1112
export async function getMockedRequestHandlers(...args: Parameters<typeof getRequestHandlers>) {
12-
const { blobStore } = await import('./cache.cjs')
13+
const store = getDeployStore()
1314
const ofs = { ...fs }
1415

1516
async function readFileFallbackBlobStore(...args: Parameters<FS['promises']['readFile']>) {
@@ -22,7 +23,7 @@ export async function getMockedRequestHandlers(...args: Parameters<typeof getReq
2223
// only try to get .html files from the blob store
2324
if (typeof path === 'string' && path.endsWith('.html')) {
2425
const blobKey = relative(join(process.cwd(), '.next'), path)
25-
const file = await blobStore.get(blobKey)
26+
const file = await store.get(blobKey)
2627
if (file !== null) {
2728
return file
2829
}

tests/e2e/page-router.test.ts

+34-13
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,51 @@ test.describe('page-router', () => {
1212
await ctx?.cleanup?.(!!testInfo.errors.length)
1313
})
1414

15-
// NOT working yet as blob storage upload ins not working with the CLI
15+
// The cache purge does not work :(
1616
test.skip('Static revalidate works correctly', async ({ page }) => {
17-
const response1 = await page.goto(new URL('static/revalidate', ctx.url).href)
17+
const response1 = await page.goto(new URL('static/revalidate-manual', ctx.url).href)
1818
const headers1 = response1?.headers() || {}
1919
expect(response1?.status()).toBe(200)
2020
expect(headers1['x-nextjs-cache']).toBe('HIT')
21-
expect(headers1['netlify-cdn-cache-control']).toBe('s-maxage=3, stale-while-revalidate')
2221

22+
const date1 = await page.textContent('[data-testid="date-now"]')
2323
const h1 = await page.textContent('h1')
2424
expect(h1).toBe('Show #71')
2525

26-
const date1 = await page.textContent('[data-testid="date-now"]')
27-
28-
// wait to have a stale page
29-
page.waitForTimeout(3_000)
30-
31-
const response2 = await page.goto(new URL('static/revalidate', ctx.url).href)
32-
const headers2 = response1?.headers() || {}
26+
const response2 = await page.goto(new URL('static/revalidate-manual', ctx.url).href)
27+
const headers2 = response2?.headers() || {}
3328
expect(response2?.status()).toBe(200)
34-
expect(response1?.status()).toBe(200)
35-
expect(headers2['x-nextjs-cache']).toBe('MISS')
29+
expect(headers2['x-nextjs-cache']).toBe('HIT')
3630

31+
// the page is cached
3732
const date2 = await page.textContent('[data-testid="date-now"]')
33+
expect(date2).toBe(date1)
34+
35+
const revalidate = await page.goto(new URL('/api/revalidate', ctx.url).href)
36+
expect(revalidate?.status()).toBe(200)
37+
38+
// wait a bit until the page got regenerated
39+
await page.waitForTimeout(100)
40+
41+
// now after the revalidation it should have a different date
42+
const response3 = await page.goto(new URL('static/revalidate-manual', ctx.url).href)
43+
const headers3 = response3?.headers() || {}
44+
expect(response3?.status()).toBe(200)
45+
expect(headers3['x-nextjs-cache']).toBe('HIT')
46+
47+
// the page has now an updated date
48+
const date3 = await page.textContent('[data-testid="date-now"]')
49+
expect(date3).not.toBe(date2)
50+
})
51+
52+
// Only works locally with the patched CLI that have blob support enable once this is released
53+
test.skip('requesting a non existing page route that needs to be fetched from the blob store like 404.html', async ({
54+
page,
55+
}) => {
56+
const response = await page.goto(new URL('non-exisitng', ctx.url).href)
57+
const headers = response?.headers() || {}
58+
expect(response?.status()).toBe(404)
3859

39-
expect(date1).not.toBe(date2)
60+
expect(await page.textContent('h1')).toBe('404')
4061
})
4162
})

tests/utils/create-e2e-fixture.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const createE2EFixture = async (fixture: string) => {
2727
let logs: string
2828
const _cleanup = (failure: boolean = false) => {
2929
if (failure) {
30+
console.log('\n\n\n🪵 Deploy Logs:')
3031
console.log(logs)
3132
}
3233
// on failures we don't delete the deploy

0 commit comments

Comments
 (0)