| |
| |
| |
| |
| @@ -9,6 +9,7 @@ describe('action-only fallback resume data cache', () => { |
| : { |
| NEXT_PRIVATE_TEST_HEADERS: '1', |
| NEXT_PRIVATE_MINIMAL_MODE: '1', |
| + TEST_CACHE_HANDLER: '1', |
| }, |
| }) |
| |
| @@ -70,6 +71,8 @@ describe('action-only fallback resume data cache', () => { |
| } |
| |
| it('handles postponed state on an action-only fallback request', async () => { |
| + const outputIndex = next.cliOutput.length |
| + |
| const response = await invokeAction('readCachedValue') |
| |
| expect(response.status).toBe(200) |
| @@ -77,15 +80,25 @@ describe('action-only fallback resume data cache', () => { |
| const responseBody = await response.text() |
| expect(responseBody).toContain('cached value') |
| expect(responseBody).not.toContain('destination page rendered') |
| + |
| + const output = next.cliOutput.slice(outputIndex) |
| + expect(output).toContain('ActionOnlyFallbackCacheHandler::updateTags') |
| + expect(output).toContain('_N_T_/events/foo/group') |
| }) |
| |
| - it('does not render the fallback route when the action calls notFound', async () => { |
| + it('applies pending revalidations without rendering the fallback route when the action calls notFound', async () => { |
| + const outputIndex = next.cliOutput.length |
| + |
| const response = await invokeAction('notFoundAfterRevalidation') |
| |
| expect(response.status).toBe(404) |
| expect(response.headers.get('content-type')).toContain('text/x-component') |
| const responseBody = await response.text() |
| expect(responseBody).not.toContain('destination page rendered') |
| + |
| + const output = next.cliOutput.slice(outputIndex) |
| + expect(output).toContain('ActionOnlyFallbackCacheHandler::updateTags') |
| + expect(output).toContain('_N_T_/events/foo/group') |
| }) |
| } |
| }) |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,23 @@ |
| +// @ts-check |
| + |
| +const defaultCacheHandler = |
| + require('next/dist/server/lib/cache-handlers/default.external').default |
| + |
| +/** |
| + * @type {import('next/dist/server/lib/cache-handlers/types').CacheHandler} |
| + */ |
| +const cacheHandler = { |
| + get: defaultCacheHandler.get.bind(defaultCacheHandler), |
| + set: defaultCacheHandler.set.bind(defaultCacheHandler), |
| + refreshTags: defaultCacheHandler.refreshTags.bind(defaultCacheHandler), |
| + getExpiration: defaultCacheHandler.getExpiration.bind(defaultCacheHandler), |
| + async updateTags(tags) { |
| + console.log( |
| + 'ActionOnlyFallbackCacheHandler::updateTags', |
| + JSON.stringify(tags) |
| + ) |
| + return defaultCacheHandler.updateTags(tags) |
| + }, |
| +} |
| + |
| +module.exports = cacheHandler |
| |
| |
| |
| |
| @@ -3,6 +3,11 @@ |
| */ |
| const nextConfig = { |
| cacheComponents: true, |
| + cacheHandlers: process.env.TEST_CACHE_HANDLER |
| + ? { |
| + default: require.resolve('./cache-handler.js'), |
| + } |
| + : undefined, |
| } |
| |
| module.exports = nextConfig |
|
|