Unverified Commit 4f5da820 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

segment cache: fix segment cache normalizer (#90111)

This fixes an issue where deploying an app that explicitly named a
catch-all segments as `[...segments]` or `[[...segments]]` would lead to
repeated ISR cache misses on that route, even if it was generated at
build time.

This is because the normalizer that is responsible for extracting the
segment path wasn't escaping the `.segments` directory value, so the `.`
was treated as a wildcard. That meant when the server attempted to look
up the underlying segment data, it wouldn't find it and would have
responded with a 204, which signals to the upstream CDN that it is not a
cacheable response.

Fixes #87090
parent 2a2b7b17
...@@ -9,4 +9,28 @@ describe('SegmentPrefixRSCPathnameNormalizer', () => { ...@@ -9,4 +9,28 @@ describe('SegmentPrefixRSCPathnameNormalizer', () => {
segmentPath: '/_tree', segmentPath: '/_tree',
}) })
}) })
it('should extract segment prefetch paths for catch-all params named segments', () => {
const normalizer = new SegmentPrefixRSCPathnameNormalizer()
const result = normalizer.extract(
'/catch/[...segments].segments/catch/$c$segments/__PAGE__.segment.rsc'
)
expect(result).toEqual({
originalPathname: '/catch/[...segments]',
segmentPath: '/catch/$c$segments/__PAGE__',
})
})
it('should still extract segment prefetch paths for other catch-all param names', () => {
const normalizer = new SegmentPrefixRSCPathnameNormalizer()
const result = normalizer.extract(
'/catch/[...foobar].segments/catch/$c$foobar/__PAGE__.segment.rsc'
)
expect(result).toEqual({
originalPathname: '/catch/[...foobar]',
segmentPath: '/catch/$c$foobar/__PAGE__',
})
})
}) })
...@@ -4,9 +4,10 @@ import { ...@@ -4,9 +4,10 @@ import {
RSC_SEGMENT_SUFFIX, RSC_SEGMENT_SUFFIX,
RSC_SEGMENTS_DIR_SUFFIX, RSC_SEGMENTS_DIR_SUFFIX,
} from '../../../lib/constants' } from '../../../lib/constants'
import { escapeStringRegexp } from '../../../shared/lib/escape-regexp'
const PATTERN = new RegExp( const PATTERN = new RegExp(
`^(/.*)${RSC_SEGMENTS_DIR_SUFFIX}(/.*)${RSC_SEGMENT_SUFFIX}$` `^(/.*)${escapeStringRegexp(RSC_SEGMENTS_DIR_SUFFIX)}(/.*)${escapeStringRegexp(RSC_SEGMENT_SUFFIX)}$`
) )
export class SegmentPrefixRSCPathnameNormalizer implements PathnameNormalizer { export class SegmentPrefixRSCPathnameNormalizer implements PathnameNormalizer {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment