Skip to content

Commit

Permalink
test: add comma cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Oct 8, 2024
1 parent 2c999c5 commit b463221
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 28 deletions.
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineConfig({
extraHTTPHeaders: {
/* Add debug logging for netlify cache headers */
'x-nf-debug-logging': '1',
'x-next-debug-logging': '1',
},
},
timeout: 10 * 60 * 1000,
Expand Down
11 changes: 7 additions & 4 deletions src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
cacheValue.kind === 'APP_ROUTE'
) {
if (cacheValue.headers?.[NEXT_CACHE_TAGS_HEADER]) {
const cacheTags = (cacheValue.headers[NEXT_CACHE_TAGS_HEADER] as string).split(',')
const cacheTags = (cacheValue.headers[NEXT_CACHE_TAGS_HEADER] as string).split(/,|%2c/gi)
requestContext.responseCacheTags = cacheTags
} else if (
(cacheValue.kind === 'PAGE' || cacheValue.kind === 'PAGES') &&
Expand Down Expand Up @@ -347,7 +347,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
const tag = `_N_T_${key === '/index' ? '/' : encodeURI(key)}`
getLogger().debug(`Purging CDN cache for: [${tag}]`)
requestContext.trackBackgroundWork(
purgeCache({ tags: [tag] }).catch((error) => {
purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => {
// TODO: add reporting here
getLogger()
.withError(error)
Expand Down Expand Up @@ -375,7 +375,9 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
private async doRevalidateTag(tagOrTags: string | string[], ...args: any) {
getLogger().withFields({ tagOrTags, args }).debug('NetlifyCacheHandler.revalidateTag')

const tags = Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]
const tags = (Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]).flatMap((tag) =>
tag.split(/,|%2c/gi),
)

const data: TagManifest = {
revalidatedAt: Date.now(),
Expand Down Expand Up @@ -422,7 +424,8 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
cacheEntry.value?.kind === 'ROUTE' ||
cacheEntry.value?.kind === 'APP_ROUTE'
) {
cacheTags = (cacheEntry.value.headers?.[NEXT_CACHE_TAGS_HEADER] as string)?.split(',') || []
cacheTags =
(cacheEntry.value.headers?.[NEXT_CACHE_TAGS_HEADER] as string)?.split(/,|%2c/gi) || []
} else {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/on-demand-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ test.describe('app router on-demand revalidation', () => {
{
label: 'revalidatePath (prerendered page with dynamic path) - non-ASCII variant',
prerendered: true,
pagePath: '/product/事前レンダリング',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリング`,
expectedH1Content: 'Product 事前レンダリング',
pagePath: '/product/事前レンダリング,test',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリング,test`,
expectedH1Content: 'Product 事前レンダリング,test',
},
{
label: 'revalidatePath (not prerendered page with dynamic path) - non-ASCII variant',
prerendered: false,
pagePath: '/product/事前レンダリングされていない',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリングされていない`,
expectedH1Content: 'Product 事前レンダリングされていない',
pagePath: '/product/事前レンダリングされていない,test',
revalidateApiPath: `/api/on-demand-revalidate/path?path=/product/事前レンダリングされていない,test`,
expectedH1Content: 'Product 事前レンダリングされていない,test',
},
]) {
test(label, async ({ page, pollUntilHeadersMatch, serverComponents }) => {
Expand Down
16 changes: 8 additions & 8 deletions tests/e2e/page-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
label:
'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
prerendered: true,
pagePath: '/products/事前レンダリング',
pagePath: '/products/事前レンダリング,test',
revalidateApiBasePath: '/api/revalidate',
expectedH1Content: 'Product 事前レンダリング',
expectedH1Content: 'Product 事前レンダリング,test',
},
{
label:
'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
prerendered: false,
pagePath: '/products/事前レンダリングされていない',
pagePath: '/products/事前レンダリングされていない,test',
revalidateApiBasePath: '/api/revalidate',
expectedH1Content: 'Product 事前レンダリングされていない',
expectedH1Content: 'Product 事前レンダリングされていない,test',
},
]) {
test(label, async ({ page, pollUntilHeadersMatch, pageRouter }) => {
Expand Down Expand Up @@ -479,17 +479,17 @@ test.describe('Page Router with basePath and i18n', () => {
label:
'prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
prerendered: true,
pagePath: '/products/事前レンダリング',
pagePath: '/products/事前レンダリング,test',
revalidateApiBasePath: '/api/revalidate',
expectedH1Content: 'Product 事前レンダリング',
expectedH1Content: 'Product 事前レンダリング,test',
},
{
label:
'not prerendered page with dynamic path and awaited res.revalidate() - non-ASCII variant',
prerendered: false,
pagePath: '/products/事前レンダリングされていない',
pagePath: '/products/事前レンダリングされていない,test',
revalidateApiBasePath: '/api/revalidate',
expectedH1Content: 'Product 事前レンダリングされていない',
expectedH1Content: 'Product 事前レンダリングされていない,test',
},
]) {
test.describe(label, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const getStaticPaths = ({ locales }) => {
},
{
params: {
// Japanese prerendered (non-ascii)
slug: '事前レンダリング',
// Japanese prerendered (non-ascii) and comma
slug: '事前レンダリング,test',
},
},
].flatMap((pathDescription) => locales.map((locale) => ({ ...pathDescription, locale }))),
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/page-router/pages/products/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const getStaticPaths = () => {
},
{
params: {
// Japanese prerendered (non-ascii)
slug: '事前レンダリング',
// Japanese prerendered (non-ascii) and comma
slug: '事前レンダリング,test',
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/server-components/app/product/[slug]/page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Product = ({ params }) => (
<div>
<h1>Product {decodeURI(params.slug)}</h1>
<h1>Product {decodeURIComponent(params.slug)}</h1>
<p>
This page uses generateStaticParams() to prerender a Product
<span data-testid="date-now">{new Date().toISOString()}</span>
Expand All @@ -11,8 +11,8 @@ const Product = ({ params }) => (
export async function generateStaticParams() {
return [
{
// Japanese prerendered (non-ascii)
slug: '事前レンダリング',
// Japanese prerendered (non-ascii) and comma
slug: '事前レンダリング,test',
},
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cache-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('page router', () => {
// the real key is much longer and ends in a hash, but we only assert on the first 50 chars to make it easier
'/products/an-incredibly-long-product-',
'/products/prerendered',
'/products/事前レンダリング',
'/products/事前レンダリング,te',
'/static/revalidate-automatic',
'/static/revalidate-manual',
'/static/revalidate-slow',
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('plugin', () => {
'/api/static/first',
'/api/static/second',
'/index',
'/product/事前レンダリング',
'/product/事前レンダリング,test',
'/revalidate-fetch',
'/static-fetch-1',
'/static-fetch-2',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test<FixtureTestContext>('requesting a non existing page route that needs to be
expect(entries.map(({ key }) => decodeBlobKey(key.substring(0, 50))).sort()).toEqual([
'/products/an-incredibly-long-product-',
'/products/prerendered',
'/products/事前レンダリング',
'/products/事前レンダリング,te',
'/static/revalidate-automatic',
'/static/revalidate-manual',
'/static/revalidate-slow',
Expand Down

0 comments on commit b463221

Please sign in to comment.