Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setting the right tag values for fetch cache #304

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
| CachedFetchValue
| CachedRouteValue;

type IncrementalCacheContext = {
revalidate?: number | false | undefined;
fetchCache?: boolean | undefined;
fetchUrl?: string | undefined;
fetchIdx?: number | undefined;
tags?: string[] | undefined;
};

interface CacheHandlerContext {
fs?: never;
dev?: boolean;
Expand Down Expand Up @@ -254,7 +262,11 @@
return null;
}

async set(key: string, data?: IncrementalCacheValue): Promise<void> {
async set(
key: string,
data?: IncrementalCacheValue,
ctx?: IncrementalCacheContext,
): Promise<void> {
if (globalThis.disableIncrementalCache) {
return;
}
Expand Down Expand Up @@ -287,7 +299,7 @@
]);
} else if (data?.kind === "FETCH") {
await this.putS3Object(key, "fetch", JSON.stringify(data));
} else if (data?.kind === "REDIRECT") {

Check warning on line 302 in packages/open-next/src/adapters/cache.ts

View workflow job for this annotation

GitHub Actions / validate

Add the missing "else" clause
// delete potential page data if we're redirecting
await this.deleteS3Objects(key);
await this.putS3Object(key, "redirect", JSON.stringify(data));
Expand All @@ -298,7 +310,7 @@
// If we use an in house version of getDerivedTags in build we should use it here instead of next's one
const derivedTags: string[] =
data?.kind === "FETCH"
? data.data.tags ?? []
? ctx?.tags ?? []
Copy link
Collaborator

@khuezy khuezy Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break backwards compatibility? Can we do ctx?.tags ??data?.data?.tags ?? []

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, that's how it should be done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated my PR with this change

: data?.kind === "PAGE"
? data.headers?.["x-next-cache-tags"]?.split(",") ?? []
: [];
Expand Down
Loading