Skip to content

fix cache control for static page with base path #880

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/afraid-trees-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix cache control headers for fully static page with base path
4 changes: 3 additions & 1 deletion packages/open-next/src/core/routing/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export function fixCacheHeaderForHtmlPages(
// https://opennext.js.org/aws/v2/advanced/workaround#workaround-nextserver-does-not-set-cache-headers-for-html-pages
// Requests containing an `x-middleware-prefetch` header must not be cached
if (
HtmlPages.includes(localizedPath) &&
HtmlPages.find(
(path) => `${NextConfig.basePath ?? ""}${path}` === localizedPath,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: instead of having to string concat time, you could compare to localizedPathFromBasePath that would be computed once before the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ho this made me realize, this might not be correct when both i18n and basePath are set.
I'll convert this one to draft and make a release in the meantime

) &&
!internalEvent.headers["x-middleware-prefetch"]
) {
headers[CommonHeaders.CACHE_CONTROL] =
Expand Down
Loading