Skip to content

Commit

Permalink
tmp: just checking if canary tests will be happier
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Aug 23, 2024
1 parent d41873b commit 89ff228
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/build/content/prerendered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const writeCacheEntry = async (
const routeToFilePath = (path: string) => (path === '/' ? '/index' : path)

const buildPagesCacheValue = async (path: string): Promise<NetlifyCachedPageValue> => ({

Check failure on line 48 in src/build/content/prerendered.ts

View workflow job for this annotation

GitHub Actions / Lint

Type '{ kind: string; html: string; pageData: any; headers: undefined; status: undefined; }' is not assignable to type 'never'.
kind: 'PAGE',
kind: 'PAGES',
html: await readFile(`${path}.html`, 'utf-8'),
pageData: JSON.parse(await readFile(`${path}.json`, 'utf-8')),
headers: undefined,
Expand Down Expand Up @@ -97,7 +97,7 @@ const buildRouteCacheValue = async (
path: string,
initialRevalidateSeconds: number | false,
): Promise<NetlifyCachedRouteValue> => ({
kind: 'ROUTE',
kind: 'APP_ROUTE',
body: await readFile(`${path}.body`, 'base64'),
...JSON.parse(await readFile(`${path}.meta`, 'utf-8')),
revalidate: initialRevalidateSeconds,
Expand Down Expand Up @@ -171,7 +171,7 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
}

// Netlify Forms are not support and require a workaround
if (value.kind === 'PAGE' || value.kind === 'APP_PAGE') {
if (value.kind === 'PAGE' || value.kind === 'PAGES' || value.kind === 'APP_PAGE') {

Check failure on line 174 in src/build/content/prerendered.ts

View workflow job for this annotation

GitHub Actions / Lint

This comparison appears to be unintentional because the types '"ROUTE" | "APP_PAGE"' and '"PAGE"' have no overlap.

Check failure on line 174 in src/build/content/prerendered.ts

View workflow job for this annotation

GitHub Actions / Lint

This comparison appears to be unintentional because the types '"ROUTE" | "APP_PAGE"' and '"PAGES"' have no overlap.
verifyNetlifyForms(ctx, value.html)
}

Expand Down
26 changes: 18 additions & 8 deletions src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ export class NetlifyCacheHandler implements CacheHandler {

if (
cacheValue.kind === 'PAGE' ||
cacheValue.kind === 'PAGES' ||

Check failure on line 135 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

This comparison appears to be unintentional because the types '"ROUTE" | "REDIRECT" | "APP_PAGE" | "IMAGE" | "FETCH"' and '"PAGES"' have no overlap.
cacheValue.kind === 'APP_PAGE' ||
cacheValue.kind === 'ROUTE'
cacheValue.kind === 'ROUTE' ||
cacheValue.kind === 'APP_ROUTE'

Check failure on line 138 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

This comparison appears to be unintentional because the types '"REDIRECT" | "IMAGE" | "FETCH"' and '"APP_ROUTE"' have no overlap.
) {
if (cacheValue.headers?.[NEXT_CACHE_TAGS_HEADER]) {
const cacheTags = (cacheValue.headers[NEXT_CACHE_TAGS_HEADER] as string).split(',')
requestContext.responseCacheTags = cacheTags
} else if (cacheValue.kind === 'PAGE' && typeof cacheValue.pageData === 'object') {
} else if (
(cacheValue.kind === 'PAGE' || cacheValue.kind === 'PAGES') &&

Check failure on line 144 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

This comparison appears to be unintentional because the types '"ROUTE" | "APP_PAGE"' and '"PAGES"' have no overlap.
typeof cacheValue.pageData === 'object'
) {
// pages router doesn't have cache tags headers in PAGE cache value
// so we need to generate appropriate cache tags for it
const cacheTags = [`_N_T_${key === '/index' ? '/' : key}`]
Expand Down Expand Up @@ -186,6 +191,7 @@ export class NetlifyCacheHandler implements CacheHandler {
}

async get(...args: Parameters<CacheHandler['get']>): ReturnType<CacheHandler['get']> {
debugger

Check failure on line 194 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'debugger' statement.
return this.tracer.withActiveSpan('get cache key', async (span) => {
const [key, ctx = {}] = args
getLogger().debug(`[NetlifyCacheHandler.get]: ${key}`)
Expand Down Expand Up @@ -224,8 +230,9 @@ export class NetlifyCacheHandler implements CacheHandler {
value: blob.value,
}

case 'ROUTE': {
span.addEvent('ROUTE', { lastModified: blob.lastModified, status: blob.value.status })
case 'ROUTE':
case 'APP_ROUTE': {

Check failure on line 234 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

Type '"APP_ROUTE"' is not comparable to type '"ROUTE" | "REDIRECT" | "PAGE" | "APP_PAGE" | "IMAGE" | "FETCH" | undefined'.
span.addEvent('APP_ROUTE', { lastModified: blob.lastModified, status: blob.value.status })

const valueWithoutRevalidate = this.captureRouteRevalidateAndRemoveFromObject(blob.value)

Expand All @@ -237,7 +244,8 @@ export class NetlifyCacheHandler implements CacheHandler {
},
}
}
case 'PAGE': {
case 'PAGE':
case 'PAGES': {

Check failure on line 248 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

Type '"PAGES"' is not comparable to type '"ROUTE" | "REDIRECT" | "PAGE" | "APP_PAGE" | "IMAGE" | "FETCH" | undefined'.
span.addEvent('PAGE', { lastModified: blob.lastModified })

const { revalidate, ...restOfPageValue } = blob.value

Check failure on line 251 in src/run/handlers/cache.cts

View workflow job for this annotation

GitHub Actions / Lint

Property 'revalidate' does not exist on type 'IncrementalCachedPageValue'.
Expand Down Expand Up @@ -275,15 +283,15 @@ export class NetlifyCacheHandler implements CacheHandler {
data: Parameters<IncrementalCache['set']>[1],
context: Parameters<IncrementalCache['set']>[2],
): NetlifyIncrementalCacheValue | null {
if (data?.kind === 'ROUTE') {
if (data?.kind === 'ROUTE' || data?.kind === 'APP_ROUTE') {
return {
...data,
revalidate: context.revalidate,
body: data.body.toString('base64'),
}
}

if (data?.kind === 'PAGE') {
if (data?.kind === 'PAGE' || data?.kind === 'PAGES') {
return {
...data,
revalidate: context.revalidate,
Expand Down Expand Up @@ -397,8 +405,10 @@ export class NetlifyCacheHandler implements CacheHandler {
cacheTags = [...tags, ...softTags]
} else if (
cacheEntry.value?.kind === 'PAGE' ||
cacheEntry.value?.kind === 'PAGES' ||
cacheEntry.value?.kind === 'APP_PAGE' ||
cacheEntry.value?.kind === 'ROUTE'
cacheEntry.value?.kind === 'ROUTE' ||
cacheEntry.value?.kind === 'APP_ROUTE'
) {
cacheTags = (cacheEntry.value.headers?.[NEXT_CACHE_TAGS_HEADER] as string)?.split(',') || []
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/cache-types.cts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type NetlifyCachedAppPageValue = Omit<IncrementalCachedAppPageValue, 'rsc
revalidate?: Parameters<IncrementalCache['set']>[2]['revalidate']
}

type CachedPageValue = Extract<IncrementalCacheValue, { kind: 'PAGE' }>
type CachedPageValue = Extract<IncrementalCacheValue, { kind: 'PAGES' }>

export type NetlifyCachedPageValue = CachedPageValue & {
revalidate?: Parameters<IncrementalCache['set']>[2]['revalidate']
Expand Down

0 comments on commit 89ff228

Please sign in to comment.